Skip to content

Commit

Permalink
Bugfix 5430 pass logs to junit report (pytest-dev#6274)
Browse files Browse the repository at this point in the history
Bugfix 5430 pass logs to junit report
  • Loading branch information
nicoddemus committed Dec 12, 2019
1 parent bd54116 commit f9ebe3c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -58,6 +58,7 @@ Christian Theunert
Christian Tismer
Christopher Gilling
Christopher Dignam
Claudio Madotto
CrazyMerlyn
Cyrus Maden
Damian Skrzypczak
Expand Down
1 change: 1 addition & 0 deletions changelog/5430.bugfix.rst
@@ -0,0 +1 @@
junitxml: Logs for failed test are now passed to junit report in case the test fails during call phase.
2 changes: 2 additions & 0 deletions src/_pytest/junitxml.py
Expand Up @@ -597,6 +597,8 @@ def pytest_runtest_logreport(self, report):
if report.when == "call":
reporter.append_failure(report)
self.open_reports.append(report)
if not self.log_passing_tests:
reporter.write_captured_output(report)
else:
reporter.append_error(report)
elif report.skipped:
Expand Down
42 changes: 42 additions & 0 deletions testing/test_junitxml.py
Expand Up @@ -1409,3 +1409,45 @@ def test_func():
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

0 comments on commit f9ebe3c

Please sign in to comment.