Include setup and teardown in junitxml test durations
--HG-- branch : include-setup-teardown-duration-in-junitxml
This commit is contained in:
parent
aa2ffb9805
commit
93628fc0eb
|
@ -96,7 +96,7 @@ class LogXML(object):
|
||||||
self.tests.append(Junit.testcase(
|
self.tests.append(Junit.testcase(
|
||||||
classname=".".join(classnames),
|
classname=".".join(classnames),
|
||||||
name=bin_xml_escape(names[-1]),
|
name=bin_xml_escape(names[-1]),
|
||||||
time=getattr(report, 'duration', 0)
|
time=0
|
||||||
))
|
))
|
||||||
|
|
||||||
def _write_captured_output(self, report):
|
def _write_captured_output(self, report):
|
||||||
|
@ -168,18 +168,18 @@ class LogXML(object):
|
||||||
self._write_captured_output(report)
|
self._write_captured_output(report)
|
||||||
|
|
||||||
def pytest_runtest_logreport(self, 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.passed:
|
||||||
if report.when == "call": # ignore setup/teardown
|
if report.when == "call": # ignore setup/teardown
|
||||||
self._opentestcase(report)
|
|
||||||
self.append_pass(report)
|
self.append_pass(report)
|
||||||
elif report.failed:
|
elif report.failed:
|
||||||
self._opentestcase(report)
|
|
||||||
if report.when != "call":
|
if report.when != "call":
|
||||||
self.append_error(report)
|
self.append_error(report)
|
||||||
else:
|
else:
|
||||||
self.append_failure(report)
|
self.append_failure(report)
|
||||||
elif report.skipped:
|
elif report.skipped:
|
||||||
self._opentestcase(report)
|
|
||||||
self.append_skipped(report)
|
self.append_skipped(report)
|
||||||
|
|
||||||
def pytest_collectreport(self, report):
|
def pytest_collectreport(self, report):
|
||||||
|
|
|
@ -44,6 +44,10 @@ class TestPython:
|
||||||
def test_timing_function(self, testdir):
|
def test_timing_function(self, testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import time, pytest
|
import time, pytest
|
||||||
|
def setup_module():
|
||||||
|
time.sleep(0.01)
|
||||||
|
def teardown_module():
|
||||||
|
time.sleep(0.01)
|
||||||
def test_sleep():
|
def test_sleep():
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
""")
|
""")
|
||||||
|
@ -51,7 +55,7 @@ class TestPython:
|
||||||
node = dom.getElementsByTagName("testsuite")[0]
|
node = dom.getElementsByTagName("testsuite")[0]
|
||||||
tnode = node.getElementsByTagName("testcase")[0]
|
tnode = node.getElementsByTagName("testcase")[0]
|
||||||
val = tnode.getAttributeNode("time").value
|
val = tnode.getAttributeNode("time").value
|
||||||
assert float(val) >= 0.001
|
assert float(val) >= 0.03
|
||||||
|
|
||||||
def test_setup_error(self, testdir):
|
def test_setup_error(self, testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
|
Loading…
Reference in New Issue