Fix teardown error message in generated xUnit XML

It was "test setup failure" even error happens on test teardown.
This commit is contained in:
Georgy Dyuldin 2016-11-02 15:45:40 +03:00
parent e3544553b7
commit e2bb4f893b
3 changed files with 34 additions and 4 deletions

View File

@ -20,7 +20,8 @@
* Report teardown output on test failure (`#442`_).
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
.. _@okulynyak: https://github.com/okulynyak
.. _@matclab: https://github.com/matclab
.. _@gdyuldin: https://github.com/gdyuldin
.. _#442: https://github.com/pytest-dev/pytest/issues/442
.. _#1976: https://github.com/pytest-dev/pytest/issues/1976

View File

@ -156,8 +156,12 @@ class _NodeReporter(object):
Junit.skipped, "collection skipped", report.longrepr)
def append_error(self, report):
if getattr(report, 'when', None) == 'teardown':
msg = "test teardown failure"
else:
msg = "test setup failure"
self._add_simple(
Junit.error, "test setup failure", report.longrepr)
Junit.error, msg, report.longrepr)
self._write_captured_output(report)
def append_skipped(self, report):

View File

@ -165,6 +165,30 @@ class TestPython:
fnode.assert_attr(message="test setup failure")
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):
testdir.makepyfile("""
import pytest