From 8dc4e732f073354039e0ea7bfa4446c94025c6ca Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 28 May 2011 14:03:10 +0200 Subject: [PATCH] fix issue47 - fix time-per-test timing output for junitxml --- CHANGELOG | 1 + _pytest/__init__.py | 2 +- _pytest/junitxml.py | 5 ++--- setup.py | 2 +- testing/test_junitxml.py | 12 ++++++++++++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9ed43af5d..b051e2067 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Changes between 2.0.3 and DEV ---------------------------------------------- +- fix issue47: timing output in junitxml for test cases is now correct - introduce XXX pytest_configure_funcargs hack (thanks Ronny) - env/username expansion for junitxml file path (fixes issue44) diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 8c9504f6e..b79038b1d 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.0.4.dev' +__version__ = '2.1.0.dev1' diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 8549e9fcd..f51771354 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -76,7 +76,7 @@ class LogXML(object): names = report.nodeid.split("::") names[0] = names[0].replace("/", '.') names = tuple(names) - d = {'time': self._durations.pop(names, "0")} + d = {'time': self._durations.pop(report.nodeid, "0")} names = [x.replace(".py", "") for x in names if x != "()"] classnames = names[:-1] if self.prefix: @@ -170,12 +170,11 @@ class LogXML(object): self.append_skipped(report) def pytest_runtest_call(self, item, __multicall__): - names = tuple(item.listnames()) start = time.time() try: return __multicall__.execute() finally: - self._durations[names] = time.time() - start + self._durations[item.nodeid] = time.time() - start def pytest_collectreport(self, report): if not report.passed: diff --git a/setup.py b/setup.py index 801dc6efd..111b8319a 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.0.4.dev', + version='2.1.0.dev1', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 4d6ed237a..562a6f24e 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -39,6 +39,18 @@ class TestPython: node = dom.getElementsByTagName("testsuite")[0] assert_attr(node, errors=0, failures=1, skips=3, tests=2) + def test_timing_function(self, testdir): + testdir.makepyfile(""" + import time, pytest + def test_sleep(): + time.sleep(0.01) + """) + result, dom = runandparse(testdir) + node = dom.getElementsByTagName("testsuite")[0] + tnode = node.getElementsByTagName("testcase")[0] + val = tnode.getAttributeNode("time").value + assert float(val) >= 0.01 + def test_setup_error(self, testdir): testdir.makepyfile(""" def pytest_funcarg__arg(request):