2 new changesets in pytest: http://bitbucket.org/hpk42/pytest/changeset/99e50c37330e/ changeset: 99e50c37330e user: RonnyPfannschmidt date: 2011-09-23 10:53:03 summary: make call durations part of the test report affected #: 2 files (-1 bytes)
--- a/_pytest/junitxml.py Fri Sep 23 07:35:47 2011 +0200 +++ b/_pytest/junitxml.py Fri Sep 23 10:53:03 2011 +0200 @@ -71,13 +71,12 @@ self.test_logs = [] self.passed = self.skipped = 0 self.failed = self.errors = 0 - self._durations = {} def _opentestcase(self, report): names = report.nodeid.split("::") names[0] = names[0].replace("/", '.') names = tuple(names) - d = {'time': self._durations.pop(report.nodeid, "0")} + d = {'time': getattr(report, 'duration', 0)} names = [x.replace(".py", "") for x in names if x != "()"] classnames = names[:-1] if self.prefix: @@ -176,13 +175,6 @@ elif report.skipped: self.append_skipped(report) - def pytest_runtest_call(self, item, __multicall__): - start = time.time() - try: - return __multicall__.execute() - finally: - self._durations[item.nodeid] = time.time() - start - def pytest_collectreport(self, report): if not report.passed: if report.failed: --- a/_pytest/runner.py Fri Sep 23 07:35:47 2011 +0200 +++ b/_pytest/runner.py Fri Sep 23 10:53:03 2011 +0200 @@ -1,6 +1,6 @@ """ basic collect and runtest protocol implementations """ -import py, sys +import py, sys, time from py._code.code import TerminalRepr def pytest_namespace(): @@ -95,12 +95,16 @@ #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when + self.start = time.time() try: - self.result = func() - except KeyboardInterrupt: - raise - except: - self.excinfo = py.code.ExceptionInfo() + try: + self.result = func() + except KeyboardInterrupt: + raise + except: + self.excinfo = py.code.ExceptionInfo() + finally: + self.stop = time.time() def __repr__(self): if self.excinfo: @@ -139,6 +143,7 @@ def pytest_runtest_makereport(item, call): when = call.when + duration = call.stop-call.start keywords = dict([(x,1) for x in item.keywords]) excinfo = call.excinfo if not call.excinfo: @@ -160,14 +165,15 @@ else: # exception in setup or teardown longrepr = item._repr_failure_py(excinfo) return TestReport(item.nodeid, item.location, - keywords, outcome, longrepr, when) + keywords, outcome, longrepr, when, + duration=duration) class TestReport(BaseReport): """ Basic test report object (also used for setup and teardown calls if they fail). """ def __init__(self, nodeid, location, - keywords, outcome, longrepr, when, sections=()): + keywords, outcome, longrepr, when, sections=(), duration=0): #: normalized collection node id self.nodeid = nodeid @@ -193,6 +199,9 @@ #: marshallable self.sections = list(sections) + #: time it took to run just the test + self.duration = duration + def __repr__(self): return "<TestReport %r when=%r outcome=%r>" % ( self.nodeid, self.when, self.outcome) http://bitbucket.org/hpk42/pytest/changeset/d1f0265f96f7/ changeset: d1f0265f96f7 user: hpk42 date: 2011-09-24 15:15:51 summary: fix issue67 - junitxml now contains correct durations. thanks ronny. affected #: 3 files (-1 bytes) --- a/CHANGELOG Sat Sep 24 14:13:24 2011 +0200 +++ b/CHANGELOG Sat Sep 24 15:15:51 2011 +0200 @@ -1,6 +1,8 @@ Changes between 2.1.1 and [next version] ---------------------------------------- +- fix issue67 / junitxml now contains correct test durations, thanks ronny + Changes between 2.1.1 and 2.1.2 ---------------------------------------- --- a/_pytest/junitxml.py Sat Sep 24 14:13:24 2011 +0200 +++ b/_pytest/junitxml.py Sat Sep 24 15:15:51 2011 +0200 @@ -71,13 +71,12 @@ self.test_logs = [] self.passed = self.skipped = 0 self.failed = self.errors = 0 - self._durations = {} def _opentestcase(self, report): names = report.nodeid.split("::") names[0] = names[0].replace("/", '.') names = tuple(names) - d = {'time': self._durations.pop(report.nodeid, "0")} + d = {'time': getattr(report, 'duration', 0)} names = [x.replace(".py", "") for x in names if x != "()"] classnames = names[:-1] if self.prefix: @@ -176,13 +175,6 @@ elif report.skipped: self.append_skipped(report) - def pytest_runtest_call(self, item, __multicall__): - start = time.time() - try: - return __multicall__.execute() - finally: - self._durations[item.nodeid] = time.time() - start - def pytest_collectreport(self, report): if not report.passed: if report.failed: --- a/_pytest/runner.py Sat Sep 24 14:13:24 2011 +0200 +++ b/_pytest/runner.py Sat Sep 24 15:15:51 2011 +0200 @@ -1,6 +1,6 @@ """ basic collect and runtest protocol implementations """ -import py, sys +import py, sys, time from py._code.code import TerminalRepr def pytest_namespace(): @@ -95,12 +95,16 @@ #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when + self.start = time.time() try: - self.result = func() - except KeyboardInterrupt: - raise - except: - self.excinfo = py.code.ExceptionInfo() + try: + self.result = func() + except KeyboardInterrupt: + raise + except: + self.excinfo = py.code.ExceptionInfo() + finally: + self.stop = time.time() def __repr__(self): if self.excinfo: @@ -139,6 +143,7 @@ def pytest_runtest_makereport(item, call): when = call.when + duration = call.stop-call.start keywords = dict([(x,1) for x in item.keywords]) excinfo = call.excinfo if not call.excinfo: @@ -160,14 +165,15 @@ else: # exception in setup or teardown longrepr = item._repr_failure_py(excinfo) return TestReport(item.nodeid, item.location, - keywords, outcome, longrepr, when) + keywords, outcome, longrepr, when, + duration=duration) class TestReport(BaseReport): """ Basic test report object (also used for setup and teardown calls if they fail). """ def __init__(self, nodeid, location, - keywords, outcome, longrepr, when, sections=()): + keywords, outcome, longrepr, when, sections=(), duration=0): #: normalized collection node id self.nodeid = nodeid @@ -193,6 +199,9 @@ #: marshallable self.sections = list(sections) + #: time it took to run just the test + self.duration = duration + def __repr__(self): return "<TestReport %r when=%r outcome=%r>" % ( self.nodeid, self.when, self.outcome) Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn