Skip to content

Commit

Permalink
Merge pull request #2041 from gdyuldin/fix_xuint_teardown
Browse files Browse the repository at this point in the history
Fix teardown error message in generated xUnit XML
  • Loading branch information
RonnyPfannschmidt authored Nov 2, 2016
2 parents e354455 + e2bb4f8 commit 45b21fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
* 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.

*


.. _@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
Expand Down Expand Up @@ -98,7 +100,7 @@
enabled. This allows proper post mortem debugging for all applications
which have significant logic in their tearDown machinery (`#1890`_). Thanks
`@mbyt`_ for the PR.

* Fix use of deprecated ``getfuncargvalue`` method in the internal doctest plugin.
Thanks `@ViviCoder`_ for the report (`#1898`_).

Expand Down Expand Up @@ -395,7 +397,7 @@ time or change existing behaviors in order to make them less surprising/more use

* Refined logic for determining the ``rootdir``, considering only valid
paths which fixes a number of issues: `#1594`_, `#1435`_ and `#1471`_.
Updated the documentation according to current behavior. Thanks to
Updated the documentation according to current behavior. Thanks to
`@blueyed`_, `@davehunt`_ and `@matthiasha`_ for the PR.

* Always include full assertion explanation. The previous behaviour was hiding
Expand Down
6 changes: 5 additions & 1 deletion _pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ def append_collect_skipped(self, report):
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):
Expand Down
24 changes: 24 additions & 0 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ def test_function(arg):
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
Expand Down

0 comments on commit 45b21fa

Please sign in to comment.