Skip to content

Commit 34925a3

Browse files
authored
Merge pull request #1799 from cryporchild/junitxml-tests-tally-fix
Fix #1798 to include errors in total tests in junit xml output.
2 parents ac5c39e + c4d9c7e commit 34925a3

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Carl Friedrich Bolz
2424
Charles Cloud
2525
Charnjit SiNGH (CCSJ)
2626
Chris Lamb
27+
Christian Boelsen
2728
Christian Theunert
2829
Christian Tismer
2930
Christopher Gilling

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
* Fixed scope overriding inside metafunc.parametrize (`#634`_).
6666
Thanks to `@Stranger6667`_ for the PR.
6767

68+
* Fixed the total tests tally in junit xml output (`#1798`_).
69+
Thanks to `@cryporchild`_ for the PR.
70+
6871
*
6972

7073
*
@@ -85,6 +88,7 @@
8588
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
8689
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
8790
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
91+
.. _#1798: https://github.com/pytest-dev/pytest/pull/1798
8892
.. _#460: https://github.com/pytest-dev/pytest/pull/460
8993
.. _#634: https://github.com/pytest-dev/pytest/issues/634
9094
.. _#717: https://github.com/pytest-dev/pytest/issues/717
@@ -93,6 +97,7 @@
9397
.. _@bagerard: https://github.com/bagerard
9498
.. _@BeyondEvil: https://github.com/BeyondEvil
9599
.. _@blueyed: https://github.com/blueyed
100+
.. _@cryporchild: https://github.com/cryporchild
96101
.. _@davehunt: https://github.com/davehunt
97102
.. _@DRMacIver: https://github.com/DRMacIver
98103
.. _@eolo999: https://github.com/eolo999

_pytest/junitxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def pytest_sessionfinish(self):
369369
suite_stop_time = time.time()
370370
suite_time_delta = suite_stop_time - self.suite_start_time
371371

372-
numtests = self.stats['passed'] + self.stats['failure'] + self.stats['skipped']
372+
numtests = self.stats['passed'] + self.stats['failure'] + self.stats['skipped'] + self.stats['error']
373373

374374
logfile.write('<?xml version="1.0" encoding="utf-8"?>')
375375
logfile.write(Junit.testsuite(

testing/test_junitxml.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,27 @@ def test_xpass():
102102
node = dom.find_first_by_tag("testsuite")
103103
node.assert_attr(name="pytest", errors=0, failures=1, skips=3, tests=5)
104104

105+
def test_summing_simple_with_errors(self, testdir):
106+
testdir.makepyfile("""
107+
import pytest
108+
@pytest.fixture
109+
def fixture():
110+
raise Exception()
111+
def test_pass():
112+
pass
113+
def test_fail():
114+
assert 0
115+
def test_error(fixture):
116+
pass
117+
@pytest.mark.xfail
118+
def test_xpass():
119+
assert 1
120+
""")
121+
result, dom = runandparse(testdir)
122+
assert result.ret
123+
node = dom.find_first_by_tag("testsuite")
124+
node.assert_attr(name="pytest", errors=1, failures=1, skips=1, tests=4)
125+
105126
def test_timing_function(self, testdir):
106127
testdir.makepyfile("""
107128
import time, pytest
@@ -128,7 +149,7 @@ def test_function(arg):
128149
result, dom = runandparse(testdir)
129150
assert result.ret
130151
node = dom.find_first_by_tag("testsuite")
131-
node.assert_attr(errors=1, tests=0)
152+
node.assert_attr(errors=1, tests=1)
132153
tnode = node.find_first_by_tag("testcase")
133154
tnode.assert_attr(
134155
file="test_setup_error.py",
@@ -195,7 +216,7 @@ def test_internal_error(self, testdir):
195216
result, dom = runandparse(testdir)
196217
assert result.ret
197218
node = dom.find_first_by_tag("testsuite")
198-
node.assert_attr(errors=1, tests=0)
219+
node.assert_attr(errors=1, tests=1)
199220
tnode = node.find_first_by_tag("testcase")
200221
tnode.assert_attr(classname="pytest", name="internal")
201222
fnode = tnode.find_first_by_tag("error")
@@ -341,7 +362,7 @@ def test_collect_error(self, testdir):
341362
result, dom = runandparse(testdir)
342363
assert result.ret
343364
node = dom.find_first_by_tag("testsuite")
344-
node.assert_attr(errors=1, tests=0)
365+
node.assert_attr(errors=1, tests=1)
345366
tnode = node.find_first_by_tag("testcase")
346367
tnode.assert_attr(
347368
file="test_collect_error.py",

0 commit comments

Comments
 (0)