Fix for issue #5430 - junit-xml: logs are not passed to junit report for tests failed not in a teardown phase

This commit is contained in:
Claudio Madotto 2019-11-24 15:20:02 +01:00
parent 69ad2026f6
commit b66dc80008
2 changed files with 43 additions and 0 deletions

View File

@ -591,6 +591,7 @@ class LogXML:
if report.when == "call":
reporter.append_failure(report)
self.open_reports.append(report)
reporter.write_captured_output(report)
else:
reporter.append_error(report)
elif report.skipped:

View File

@ -1477,3 +1477,45 @@ def test_logging_passing_tests_disabled_does_not_log_test_output(
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
@parametrize_families
@pytest.mark.parametrize("junit_logging", ["no", "system-out", "system-err"])
def test_logging_passing_tests_disabled_logs_output_for_failing_test_issue5430(
testdir, junit_logging, run_and_parse, xunit_family
):
testdir.makeini(
"""
[pytest]
junit_log_passing_tests=False
junit_family={family}
""".format(
family=xunit_family
)
)
testdir.makepyfile(
"""
import pytest
import logging
import sys
def test_func():
logging.warning('hello')
assert 0
"""
)
result, dom = run_and_parse(
"-o", "junit_logging=%s" % junit_logging, family=xunit_family
)
assert result.ret == 1
node = dom.find_first_by_tag("testcase")
if junit_logging == "system-out":
assert len(node.find_by_tag("system-err")) == 0
assert len(node.find_by_tag("system-out")) == 1
elif junit_logging == "system-err":
assert len(node.find_by_tag("system-err")) == 1
assert len(node.find_by_tag("system-out")) == 0
else:
assert junit_logging == "no"
assert len(node.find_by_tag("system-err")) == 0
assert len(node.find_by_tag("system-out")) == 0