Skip to content

Commit 66c1a12

Browse files
authored
Bugfix 5430 pass logs to junit report (#6274)
Bugfix 5430 pass logs to junit report
2 parents 8cdf9d4 + 83182b8 commit 66c1a12

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Christian Theunert
6161
Christian Tismer
6262
Christopher Gilling
6363
Christopher Dignam
64+
Claudio Madotto
6465
CrazyMerlyn
6566
Cyrus Maden
6667
Damian Skrzypczak

changelog/5430.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
junitxml: Logs for failed test are now passed to junit report in case the test fails during call phase.

src/_pytest/junitxml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ def pytest_runtest_logreport(self, report):
591591
if report.when == "call":
592592
reporter.append_failure(report)
593593
self.open_reports.append(report)
594+
if not self.log_passing_tests:
595+
reporter.write_captured_output(report)
594596
else:
595597
reporter.append_error(report)
596598
elif report.skipped:

testing/test_junitxml.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,3 +1477,45 @@ def test_func():
14771477
node = dom.find_first_by_tag("testcase")
14781478
assert len(node.find_by_tag("system-err")) == 0
14791479
assert len(node.find_by_tag("system-out")) == 0
1480+
1481+
1482+
@parametrize_families
1483+
@pytest.mark.parametrize("junit_logging", ["no", "system-out", "system-err"])
1484+
def test_logging_passing_tests_disabled_logs_output_for_failing_test_issue5430(
1485+
testdir, junit_logging, run_and_parse, xunit_family
1486+
):
1487+
testdir.makeini(
1488+
"""
1489+
[pytest]
1490+
junit_log_passing_tests=False
1491+
junit_family={family}
1492+
""".format(
1493+
family=xunit_family
1494+
)
1495+
)
1496+
testdir.makepyfile(
1497+
"""
1498+
import pytest
1499+
import logging
1500+
import sys
1501+
1502+
def test_func():
1503+
logging.warning('hello')
1504+
assert 0
1505+
"""
1506+
)
1507+
result, dom = run_and_parse(
1508+
"-o", "junit_logging=%s" % junit_logging, family=xunit_family
1509+
)
1510+
assert result.ret == 1
1511+
node = dom.find_first_by_tag("testcase")
1512+
if junit_logging == "system-out":
1513+
assert len(node.find_by_tag("system-err")) == 0
1514+
assert len(node.find_by_tag("system-out")) == 1
1515+
elif junit_logging == "system-err":
1516+
assert len(node.find_by_tag("system-err")) == 1
1517+
assert len(node.find_by_tag("system-out")) == 0
1518+
else:
1519+
assert junit_logging == "no"
1520+
assert len(node.find_by_tag("system-err")) == 0
1521+
assert len(node.find_by_tag("system-out")) == 0

0 commit comments

Comments
 (0)