Add details to error message for junit (#7390)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
parent
3624acb665
commit
617bf8be5b
|
@ -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 "ValueError: Some error during setup"">
|
|
@ -236,10 +236,16 @@ class _NodeReporter:
|
||||||
self._add_simple(Junit.skipped, "collection skipped", report.longrepr)
|
self._add_simple(Junit.skipped, "collection skipped", report.longrepr)
|
||||||
|
|
||||||
def append_error(self, report: TestReport) -> None:
|
def append_error(self, report: TestReport) -> None:
|
||||||
if report.when == "teardown":
|
assert report.longrepr is not None
|
||||||
msg = "test teardown failure"
|
if getattr(report.longrepr, "reprcrash", None) is not None:
|
||||||
|
reason = report.longrepr.reprcrash.message
|
||||||
else:
|
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)
|
self._add_simple(Junit.error, msg, report.longrepr)
|
||||||
|
|
||||||
def append_skipped(self, report: TestReport) -> None:
|
def append_skipped(self, report: TestReport) -> None:
|
||||||
|
|
|
@ -266,7 +266,7 @@ class TestPython:
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def arg(request):
|
def arg(request):
|
||||||
raise ValueError()
|
raise ValueError("Error reason")
|
||||||
def test_function(arg):
|
def test_function(arg):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
|
@ -278,7 +278,7 @@ class TestPython:
|
||||||
tnode = node.find_first_by_tag("testcase")
|
tnode = node.find_first_by_tag("testcase")
|
||||||
tnode.assert_attr(classname="test_setup_error", name="test_function")
|
tnode.assert_attr(classname="test_setup_error", name="test_function")
|
||||||
fnode = tnode.find_first_by_tag("error")
|
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()
|
assert "ValueError" in fnode.toxml()
|
||||||
|
|
||||||
@parametrize_families
|
@parametrize_families
|
||||||
|
@ -290,7 +290,7 @@ class TestPython:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def arg():
|
def arg():
|
||||||
yield
|
yield
|
||||||
raise ValueError()
|
raise ValueError('Error reason')
|
||||||
def test_function(arg):
|
def test_function(arg):
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
|
@ -301,7 +301,7 @@ class TestPython:
|
||||||
tnode = node.find_first_by_tag("testcase")
|
tnode = node.find_first_by_tag("testcase")
|
||||||
tnode.assert_attr(classname="test_teardown_error", name="test_function")
|
tnode.assert_attr(classname="test_teardown_error", name="test_function")
|
||||||
fnode = tnode.find_first_by_tag("error")
|
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()
|
assert "ValueError" in fnode.toxml()
|
||||||
|
|
||||||
@parametrize_families
|
@parametrize_families
|
||||||
|
@ -328,7 +328,9 @@ class TestPython:
|
||||||
fnode = first.find_first_by_tag("failure")
|
fnode = first.find_first_by_tag("failure")
|
||||||
fnode.assert_attr(message="Exception: Call Exception")
|
fnode.assert_attr(message="Exception: Call Exception")
|
||||||
snode = second.find_first_by_tag("error")
|
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
|
@parametrize_families
|
||||||
def test_skip_contains_name_reason(self, testdir, run_and_parse, xunit_family):
|
def test_skip_contains_name_reason(self, testdir, run_and_parse, xunit_family):
|
||||||
|
|
Loading…
Reference in New Issue