Include setup and teardown in junitxml test durations

--HG--
branch : include-setup-teardown-duration-in-junitxml
This commit is contained in:
Janne Vanhala 2015-05-01 14:55:52 +03:00
parent aa2ffb9805
commit 93628fc0eb
2 changed files with 9 additions and 5 deletions

View File

@ -96,7 +96,7 @@ class LogXML(object):
self.tests.append(Junit.testcase(
classname=".".join(classnames),
name=bin_xml_escape(names[-1]),
time=getattr(report, 'duration', 0)
time=0
))
def _write_captured_output(self, report):
@ -168,18 +168,18 @@ class LogXML(object):
self._write_captured_output(report)
def pytest_runtest_logreport(self, report):
if report.when == "setup":
self._opentestcase(report)
self.tests[-1].attr.time += getattr(report, 'duration', 0)
if report.passed:
if report.when == "call": # ignore setup/teardown
self._opentestcase(report)
self.append_pass(report)
elif report.failed:
self._opentestcase(report)
if report.when != "call":
self.append_error(report)
else:
self.append_failure(report)
elif report.skipped:
self._opentestcase(report)
self.append_skipped(report)
def pytest_collectreport(self, report):

View File

@ -44,6 +44,10 @@ class TestPython:
def test_timing_function(self, testdir):
testdir.makepyfile("""
import time, pytest
def setup_module():
time.sleep(0.01)
def teardown_module():
time.sleep(0.01)
def test_sleep():
time.sleep(0.01)
""")
@ -51,7 +55,7 @@ class TestPython:
node = dom.getElementsByTagName("testsuite")[0]
tnode = node.getElementsByTagName("testcase")[0]
val = tnode.getAttributeNode("time").value
assert float(val) >= 0.001
assert float(val) >= 0.03
def test_setup_error(self, testdir):
testdir.makepyfile("""