Add the junit_log_passing_tests ini flag to skip logging output for passing tests. (#5052)
Add the junit_log_passing_tests ini flag to skip logging output for passing tests.
This commit is contained in:
commit
b10f28949d
|
@ -0,0 +1 @@
|
||||||
|
Added the ``junit_log_passing_tests`` ini value which can be used to enable and disable logging passing test output in the Junit XML file.
|
|
@ -167,6 +167,9 @@ class _NodeReporter(object):
|
||||||
self.append(node)
|
self.append(node)
|
||||||
|
|
||||||
def write_captured_output(self, report):
|
def write_captured_output(self, report):
|
||||||
|
if not self.xml.log_passing_tests and report.passed:
|
||||||
|
return
|
||||||
|
|
||||||
content_out = report.capstdout
|
content_out = report.capstdout
|
||||||
content_log = report.caplog
|
content_log = report.caplog
|
||||||
content_err = report.capstderr
|
content_err = report.capstderr
|
||||||
|
@ -414,6 +417,12 @@ def pytest_addoption(parser):
|
||||||
"one of no|system-out|system-err",
|
"one of no|system-out|system-err",
|
||||||
default="no",
|
default="no",
|
||||||
) # choices=['no', 'stdout', 'stderr'])
|
) # choices=['no', 'stdout', 'stderr'])
|
||||||
|
parser.addini(
|
||||||
|
"junit_log_passing_tests",
|
||||||
|
"Capture log information for passing tests to JUnit report: ",
|
||||||
|
type="bool",
|
||||||
|
default=True,
|
||||||
|
)
|
||||||
parser.addini(
|
parser.addini(
|
||||||
"junit_duration_report",
|
"junit_duration_report",
|
||||||
"Duration time to report: one of total|call",
|
"Duration time to report: one of total|call",
|
||||||
|
@ -437,6 +446,7 @@ def pytest_configure(config):
|
||||||
config.getini("junit_logging"),
|
config.getini("junit_logging"),
|
||||||
config.getini("junit_duration_report"),
|
config.getini("junit_duration_report"),
|
||||||
config.getini("junit_family"),
|
config.getini("junit_family"),
|
||||||
|
config.getini("junit_log_passing_tests"),
|
||||||
)
|
)
|
||||||
config.pluginmanager.register(config._xml)
|
config.pluginmanager.register(config._xml)
|
||||||
|
|
||||||
|
@ -472,12 +482,14 @@ class LogXML(object):
|
||||||
logging="no",
|
logging="no",
|
||||||
report_duration="total",
|
report_duration="total",
|
||||||
family="xunit1",
|
family="xunit1",
|
||||||
|
log_passing_tests=True,
|
||||||
):
|
):
|
||||||
logfile = os.path.expanduser(os.path.expandvars(logfile))
|
logfile = os.path.expanduser(os.path.expandvars(logfile))
|
||||||
self.logfile = os.path.normpath(os.path.abspath(logfile))
|
self.logfile = os.path.normpath(os.path.abspath(logfile))
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
self.suite_name = suite_name
|
self.suite_name = suite_name
|
||||||
self.logging = logging
|
self.logging = logging
|
||||||
|
self.log_passing_tests = log_passing_tests
|
||||||
self.report_duration = report_duration
|
self.report_duration = report_duration
|
||||||
self.family = family
|
self.family = family
|
||||||
self.stats = dict.fromkeys(["error", "passed", "failure", "skipped"], 0)
|
self.stats = dict.fromkeys(["error", "passed", "failure", "skipped"], 0)
|
||||||
|
|
|
@ -1332,3 +1332,30 @@ def test_escaped_skipreason_issue3533(testdir):
|
||||||
snode = node.find_first_by_tag("skipped")
|
snode = node.find_first_by_tag("skipped")
|
||||||
assert "1 <> 2" in snode.text
|
assert "1 <> 2" in snode.text
|
||||||
snode.assert_attr(message="1 <> 2")
|
snode.assert_attr(message="1 <> 2")
|
||||||
|
|
||||||
|
|
||||||
|
def test_logging_passing_tests_disabled_does_not_log_test_output(testdir):
|
||||||
|
testdir.makeini(
|
||||||
|
"""
|
||||||
|
[pytest]
|
||||||
|
junit_log_passing_tests=False
|
||||||
|
junit_logging=system-out
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def test_func():
|
||||||
|
sys.stdout.write('This is stdout')
|
||||||
|
sys.stderr.write('This is stderr')
|
||||||
|
logging.warning('hello')
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result, dom = runandparse(testdir)
|
||||||
|
assert result.ret == 0
|
||||||
|
node = dom.find_first_by_tag("testcase")
|
||||||
|
assert len(node.find_by_tag("system-err")) == 0
|
||||||
|
assert len(node.find_by_tag("system-out")) == 0
|
||||||
|
|
Loading…
Reference in New Issue