Add details to error message for junit (#7390)

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
David Diaz Barquero 2020-06-23 10:03:46 -06:00 committed by GitHub
parent 3624acb665
commit 617bf8be5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 8 deletions

View File

@ -0,0 +1,13 @@
``--junitxml`` now includes the exception cause in the ``message`` XML attribute for failures during setup and teardown.
Previously:
.. code-block:: xml
<error message="test setup failure">
Now:
.. code-block:: xml
<error message="failed on setup with &quot;ValueError: Some error during setup&quot;">

View File

@ -236,10 +236,16 @@ class _NodeReporter:
self._add_simple(Junit.skipped, "collection skipped", report.longrepr)
def append_error(self, report: TestReport) -> None:
if report.when == "teardown":
msg = "test teardown failure"
assert report.longrepr is not None
if getattr(report.longrepr, "reprcrash", None) is not None:
reason = report.longrepr.reprcrash.message
else:
msg = "test setup failure"
reason = str(report.longrepr)
if report.when == "teardown":
msg = 'failed on teardown with "{}"'.format(reason)
else:
msg = 'failed on setup with "{}"'.format(reason)
self._add_simple(Junit.error, msg, report.longrepr)
def append_skipped(self, report: TestReport) -> None:

View File

@ -266,7 +266,7 @@ class TestPython:
@pytest.fixture
def arg(request):
raise ValueError()
raise ValueError("Error reason")
def test_function(arg):
pass
"""
@ -278,7 +278,7 @@ class TestPython:
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(classname="test_setup_error", name="test_function")
fnode = tnode.find_first_by_tag("error")
fnode.assert_attr(message="test setup failure")
fnode.assert_attr(message='failed on setup with "ValueError: Error reason"')
assert "ValueError" in fnode.toxml()
@parametrize_families
@ -290,7 +290,7 @@ class TestPython:
@pytest.fixture
def arg():
yield
raise ValueError()
raise ValueError('Error reason')
def test_function(arg):
pass
"""
@ -301,7 +301,7 @@ class TestPython:
tnode = node.find_first_by_tag("testcase")
tnode.assert_attr(classname="test_teardown_error", name="test_function")
fnode = tnode.find_first_by_tag("error")
fnode.assert_attr(message="test teardown failure")
fnode.assert_attr(message='failed on teardown with "ValueError: Error reason"')
assert "ValueError" in fnode.toxml()
@parametrize_families
@ -328,7 +328,9 @@ class TestPython:
fnode = first.find_first_by_tag("failure")
fnode.assert_attr(message="Exception: Call Exception")
snode = second.find_first_by_tag("error")
snode.assert_attr(message="test teardown failure")
snode.assert_attr(
message='failed on teardown with "Exception: Teardown Exception"'
)
@parametrize_families
def test_skip_contains_name_reason(self, testdir, run_and_parse, xunit_family):