Fix teardown error message in generated xUnit XML
It was "test setup failure" even error happens on test teardown.
This commit is contained in:
parent
e3544553b7
commit
e2bb4f893b
|
@ -20,7 +20,8 @@
|
||||||
* Report teardown output on test failure (`#442`_).
|
* Report teardown output on test failure (`#442`_).
|
||||||
Thanks `@matclab`_ or the PR.
|
Thanks `@matclab`_ or the PR.
|
||||||
|
|
||||||
*
|
* Fix teardown error message in generated xUnit XML.
|
||||||
|
Thanks `@gdyuldin`_ or the PR.
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@
|
||||||
.. _@cwitty: https://github.com/cwitty
|
.. _@cwitty: https://github.com/cwitty
|
||||||
.. _@okulynyak: https://github.com/okulynyak
|
.. _@okulynyak: https://github.com/okulynyak
|
||||||
.. _@matclab: https://github.com/matclab
|
.. _@matclab: https://github.com/matclab
|
||||||
|
.. _@gdyuldin: https://github.com/gdyuldin
|
||||||
|
|
||||||
.. _#442: https://github.com/pytest-dev/pytest/issues/442
|
.. _#442: https://github.com/pytest-dev/pytest/issues/442
|
||||||
.. _#1976: https://github.com/pytest-dev/pytest/issues/1976
|
.. _#1976: https://github.com/pytest-dev/pytest/issues/1976
|
||||||
|
|
|
@ -156,8 +156,12 @@ class _NodeReporter(object):
|
||||||
Junit.skipped, "collection skipped", report.longrepr)
|
Junit.skipped, "collection skipped", report.longrepr)
|
||||||
|
|
||||||
def append_error(self, report):
|
def append_error(self, report):
|
||||||
|
if getattr(report, 'when', None) == 'teardown':
|
||||||
|
msg = "test teardown failure"
|
||||||
|
else:
|
||||||
|
msg = "test setup failure"
|
||||||
self._add_simple(
|
self._add_simple(
|
||||||
Junit.error, "test setup failure", report.longrepr)
|
Junit.error, msg, report.longrepr)
|
||||||
self._write_captured_output(report)
|
self._write_captured_output(report)
|
||||||
|
|
||||||
def append_skipped(self, report):
|
def append_skipped(self, report):
|
||||||
|
|
|
@ -165,6 +165,30 @@ class TestPython:
|
||||||
fnode.assert_attr(message="test setup failure")
|
fnode.assert_attr(message="test setup failure")
|
||||||
assert "ValueError" in fnode.toxml()
|
assert "ValueError" in fnode.toxml()
|
||||||
|
|
||||||
|
def test_teardown_error(self, testdir):
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def arg():
|
||||||
|
yield
|
||||||
|
raise ValueError()
|
||||||
|
def test_function(arg):
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result, dom = runandparse(testdir)
|
||||||
|
assert result.ret
|
||||||
|
node = dom.find_first_by_tag("testsuite")
|
||||||
|
tnode = node.find_first_by_tag("testcase")
|
||||||
|
tnode.assert_attr(
|
||||||
|
file="test_teardown_error.py",
|
||||||
|
line="6",
|
||||||
|
classname="test_teardown_error",
|
||||||
|
name="test_function")
|
||||||
|
fnode = tnode.find_first_by_tag("error")
|
||||||
|
fnode.assert_attr(message="test teardown failure")
|
||||||
|
assert "ValueError" in fnode.toxml()
|
||||||
|
|
||||||
def test_skip_contains_name_reason(self, testdir):
|
def test_skip_contains_name_reason(self, testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
Loading…
Reference in New Issue