From e4028b4505148804fe30634a49980b4fc7de9a37 Mon Sep 17 00:00:00 2001 From: Christian Boelsen Date: Mon, 8 Aug 2016 13:29:20 +0100 Subject: [PATCH 1/2] Fix #1798 to include errors in total tests in junit xml output. --- AUTHORS | 1 + CHANGELOG.rst | 3 +++ _pytest/junitxml.py | 2 +- testing/test_junitxml.py | 27 ++++++++++++++++++++++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0d5e1bb64..254207071 100644 --- a/AUTHORS +++ b/AUTHORS @@ -24,6 +24,7 @@ Carl Friedrich Bolz Charles Cloud Charnjit SiNGH (CCSJ) Chris Lamb +Christian Boelsen Christian Theunert Christian Tismer Christopher Gilling diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5cebf083d..ca2672f53 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -65,6 +65,8 @@ * Fixed scope overriding inside metafunc.parametrize (`#634`_). Thanks to `@Stranger6667`_ for the PR. +* Fixed the total tests tally in junit xml output (`#1798`_). + * * @@ -85,6 +87,7 @@ .. _#1597: https://github.com/pytest-dev/pytest/pull/1597 .. _#1605: https://github.com/pytest-dev/pytest/issues/1605 .. _#1626: https://github.com/pytest-dev/pytest/pull/1626 +.. _#1798: https://github.com/pytest-dev/pytest/pull/1798 .. _#460: https://github.com/pytest-dev/pytest/pull/460 .. _#634: https://github.com/pytest-dev/pytest/issues/634 .. _#717: https://github.com/pytest-dev/pytest/issues/717 diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 4c2b9d149..6041cb6f0 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -369,7 +369,7 @@ class LogXML(object): suite_stop_time = time.time() suite_time_delta = suite_stop_time - self.suite_start_time - numtests = self.stats['passed'] + self.stats['failure'] + self.stats['skipped'] + numtests = self.stats['passed'] + self.stats['failure'] + self.stats['skipped'] + self.stats['error'] logfile.write('') logfile.write(Junit.testsuite( diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index a4f10dec5..c29381a86 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -102,6 +102,27 @@ class TestPython: node = dom.find_first_by_tag("testsuite") node.assert_attr(name="pytest", errors=0, failures=1, skips=3, tests=5) + def test_summing_simple_with_errors(self, testdir): + testdir.makepyfile(""" + import pytest + @pytest.fixture + def fixture(): + raise Exception() + def test_pass(): + pass + def test_fail(): + assert 0 + def test_error(fixture): + pass + @pytest.mark.xfail + def test_xpass(): + assert 1 + """) + result, dom = runandparse(testdir) + assert result.ret + node = dom.find_first_by_tag("testsuite") + node.assert_attr(name="pytest", errors=1, failures=1, skips=1, tests=4) + def test_timing_function(self, testdir): testdir.makepyfile(""" import time, pytest @@ -128,7 +149,7 @@ class TestPython: result, dom = runandparse(testdir) assert result.ret node = dom.find_first_by_tag("testsuite") - node.assert_attr(errors=1, tests=0) + node.assert_attr(errors=1, tests=1) tnode = node.find_first_by_tag("testcase") tnode.assert_attr( file="test_setup_error.py", @@ -195,7 +216,7 @@ class TestPython: result, dom = runandparse(testdir) assert result.ret node = dom.find_first_by_tag("testsuite") - node.assert_attr(errors=1, tests=0) + node.assert_attr(errors=1, tests=1) tnode = node.find_first_by_tag("testcase") tnode.assert_attr(classname="pytest", name="internal") fnode = tnode.find_first_by_tag("error") @@ -341,7 +362,7 @@ class TestPython: result, dom = runandparse(testdir) assert result.ret node = dom.find_first_by_tag("testsuite") - node.assert_attr(errors=1, tests=0) + node.assert_attr(errors=1, tests=1) tnode = node.find_first_by_tag("testcase") tnode.assert_attr( file="test_collect_error.py", From c4d9c7ea55db731b40764dcad7abbf0692690f8f Mon Sep 17 00:00:00 2001 From: Christian Boelsen Date: Mon, 8 Aug 2016 13:45:10 +0100 Subject: [PATCH 2/2] Add thanks as requested. --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ca2672f53..ed7adaf2e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -66,6 +66,7 @@ Thanks to `@Stranger6667`_ for the PR. * Fixed the total tests tally in junit xml output (`#1798`_). + Thanks to `@cryporchild`_ for the PR. * @@ -96,6 +97,7 @@ .. _@bagerard: https://github.com/bagerard .. _@BeyondEvil: https://github.com/BeyondEvil .. _@blueyed: https://github.com/blueyed +.. _@cryporchild: https://github.com/cryporchild .. _@davehunt: https://github.com/davehunt .. _@DRMacIver: https://github.com/DRMacIver .. _@eolo999: https://github.com/eolo999