Skip to content

Commit

Permalink
Add classname to target data reported by pytest (pantsbuild#4675)
Browse files Browse the repository at this point in the history
### Problem

The target data being reported by pytest and junit are inconsistent. 

### Solution

In order to make the reports consistent, we need to add the classname to the test data being reported.

### Result

The result is that there is a classname field in the test data being reported.
  • Loading branch information
dotordogh authored and Stu Hood committed Jun 16, 2017
1 parent edd039b commit e1eacc7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/python/pants/backend/python/tasks2/pytest_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ def parse_error_handler(parse_error):
raise TaskError('Error parsing xml file at {}: {}'
.format(parse_error.xml_path, parse_error.cause))

all_tests_info = self.parse_test_info(junitxml_path, parse_error_handler, ['file', 'name'])
all_tests_info = self.parse_test_info(junitxml_path, parse_error_handler,
['file', 'name', 'classname'])
for test_name, test_info in all_tests_info.items():
test_target = self._get_target_from_test(test_info, targets)
self.report_all_info_for_single_test(self.options_scope, test_target, test_name, test_info)
Expand Down
5 changes: 4 additions & 1 deletion src/python/pants/task/testrunner_task_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ def parse_xml_file(path):
test_info.update({'time': None})

for attribute in testcase_attributes:
test_info[attribute] = testcase.getAttribute(attribute)
attribute_value = testcase.getAttribute(attribute)
if not attribute_value:
attribute_value = None
test_info[attribute] = attribute_value

test_error = testcase.getElementsByTagName('error')
test_fail = testcase.getElementsByTagName('failure')
Expand Down
8 changes: 4 additions & 4 deletions tests/python/pants_test/task/test_testrunner_task_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def test_parse_test_info_extra_attributes(self):
'time': 1.290
},
'testOK2': {
'file': '',
'file': None,
'classname': 'org.pantsbuild.Green',
'result_code': 'success',
'time': 1.12
Expand All @@ -557,13 +557,13 @@ def test_parse_test_info_extra_attributes(self):
},
'testOK4': {
'file': 'file.py',
'classname': '',
'classname': None,
'result_code': 'success',
'time': 1.79
},
'testOK5': {
'file': '',
'classname': '',
'file': None,
'classname': None,
'result_code': 'success',
'time': 0.832
},
Expand Down

0 comments on commit e1eacc7

Please sign in to comment.