Merge pull request #4529 from aparamon/jxmlunit-call-time

Add --junittime=call option
This commit is contained in:
Bruno Oliveira
2018-12-13 13:51:06 -02:00
committed by GitHub
5 changed files with 51 additions and 3 deletions

View File

@@ -323,6 +323,9 @@ def pytest_addoption(parser):
"one of no|system-out|system-err",
default="no",
) # choices=['no', 'stdout', 'stderr'])
parser.addini(
"junit_time", "Duration time to report: one of total|call", default="total"
) # choices=['total', 'call'])
def pytest_configure(config):
@@ -334,6 +337,7 @@ def pytest_configure(config):
config.option.junitprefix,
config.getini("junit_suite_name"),
config.getini("junit_logging"),
config.getini("junit_time"),
)
config.pluginmanager.register(config._xml)
@@ -361,12 +365,20 @@ def mangle_test_address(address):
class LogXML(object):
def __init__(self, logfile, prefix, suite_name="pytest", logging="no"):
def __init__(
self,
logfile,
prefix,
suite_name="pytest",
logging="no",
report_duration="total",
):
logfile = os.path.expanduser(os.path.expandvars(logfile))
self.logfile = os.path.normpath(os.path.abspath(logfile))
self.prefix = prefix
self.suite_name = suite_name
self.logging = logging
self.report_duration = report_duration
self.stats = dict.fromkeys(["error", "passed", "failure", "skipped"], 0)
self.node_reporters = {} # nodeid -> _NodeReporter
self.node_reporters_ordered = []
@@ -500,8 +512,9 @@ class LogXML(object):
"""accumulates total duration for nodeid from given report and updates
the Junit.testcase with the new total if already created.
"""
reporter = self.node_reporter(report)
reporter.duration += getattr(report, "duration", 0.0)
if self.report_duration == "total" or report.when == self.report_duration:
reporter = self.node_reporter(report)
reporter.duration += getattr(report, "duration", 0.0)
def pytest_collectreport(self, report):
if not report.passed: