Skip to content

Commit e4028b4

Browse files
author
Christian Boelsen
committed
Fix #1798 to include errors in total tests in junit xml output.
1 parent ac5c39e commit e4028b4

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

AUTHORS

+1
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

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
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+
6870
*
6971

7072
*
@@ -85,6 +87,7 @@
8587
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
8688
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
8789
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
90+
.. _#1798: https://github.com/pytest-dev/pytest/pull/1798
8891
.. _#460: https://github.com/pytest-dev/pytest/pull/460
8992
.. _#634: https://github.com/pytest-dev/pytest/issues/634
9093
.. _#717: https://github.com/pytest-dev/pytest/issues/717

_pytest/junitxml.py

+1-1
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

+24-3
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)