Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report error as well as failure #401

Merged
merged 3 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented here.

## [unreleased]
- Remove support for python3.6 and add support for python3.10 (#399)
- Fix a bug in the java tester where errors were not reported (#401)
- Add explicit namespaces to R test runner script so that test code will not interfere with result reporting (#407)

## [v2.2.1]
Expand Down
28 changes: 23 additions & 5 deletions server/autotest_server/testers/java/java_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ def _get_sources(self) -> Set:
scripts = ":".join(self.specs["test_data", "script_files"] + [sources])
return {path for path in self._parse_file_paths(scripts) if os.path.splitext(path)[1] == ".java"}

def _parse_failure_error(self, failure, error):
"""
Return a dictionary containing a status and message for either a failure, error, or both. If both
an error and failure are present, the message includes information for both.
"""
result = {}
if failure and error:
failure_message = self._parse_failure_error(failure, None)["message"]
error_message = self._parse_failure_error(None, error)["message"]
result["status"] = "error"
result["message"] = "\n\n".join([error_message, failure_message])
elif failure:
result["status"] = "failure"
result["message"] = f'{failure.attrib.get("type", "")}: {failure.attrib.get("message", "")}'
elif error:
result["status"] = "error"
result["message"] = f'{error.attrib.get("type", "")}: {error.attrib.get("message", "")}'
return result

def _parse_junitxml(self):
"""
Parse junit results and yield a hash containing result data for each testcase.
Expand All @@ -78,11 +97,10 @@ def _parse_junitxml(self):
result["name"] = "{}.{}".format(classname, testname)
result["time"] = float(testcase.attrib.get("time", 0))
failure = testcase.find("failure")
if failure is not None:
result["status"] = "failure"
failure_type = failure.attrib.get("type", "")
failure_message = failure.attrib.get("message", "")
result["message"] = f"{failure_type}: {failure_message}"
error = testcase.find("error")
fe_result = self._parse_failure_error(failure, error)
if fe_result:
result.update(fe_result)
else:
result["status"] = "success"
result["message"] = ""
Expand Down