Skip to content

Commit

Permalink
refactor: Display multiple failure elements in JUnit XML
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Apr 27, 2020
1 parent 77d8b97 commit 0a0ec07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/schemathesis/cli/junitxml.py
Expand Up @@ -20,16 +20,18 @@ def handle_event(self, context: ExecutionContext, event: events.ExecutionEvent)
if isinstance(event, events.Initialized):
self.start_time = event.start_time
if isinstance(event, events.AfterExecution):
test_case = TestCase(f"{event.result.method} {event.result.path}", elapsed_sec=event.elapsed_time)
test_case = TestCase(
f"{event.result.method} {event.result.path}",
elapsed_sec=event.elapsed_time,
allow_multiple_subelements=True,
)
if event.status == Status.failure:
checks = get_unique_failures(event.result.checks)
for idx, check in enumerate(checks, 1):
message: Optional[str]
message: Optional[str] = None
if check.message:
message = f"{idx}. {check.message}"
else:
message = None
test_case.add_failure_info(message=message)
test_case.add_failure_info(message=message)
if event.status == Status.error:
test_case.add_error_info(
message=event.result.errors[-1].exception, output=event.result.errors[-1].exception_with_traceback
Expand Down
5 changes: 4 additions & 1 deletion test/cli/test_junitxml.py
Expand Up @@ -43,7 +43,10 @@ def test_junitxml_file(cli, schema_url, tmp_path):
assert testcases[0].attrib["name"] == "GET /api/failure"
assert testcases[0][0].tag == "failure"
assert testcases[0][0].attrib["type"] == "failure"
assert testcases[0][0].attrib["message"] == "2. Received a response with 5xx status code: 500"
assert (
testcases[0][0].attrib["message"] == "1. Received a response with 'text/plain; charset=utf-8' Content-Type, "
"but it is not declared in the schema. Defined content types: application/json"
)
# Inspect testcase with an error
assert testcases[1].attrib["name"] == "GET /api/malformed_json"
assert testcases[1][0].tag == "error"
Expand Down

0 comments on commit 0a0ec07

Please sign in to comment.