From c17297d5e97d336f81aacb72049f82d74b299d85 Mon Sep 17 00:00:00 2001 From: anb76ru Date: Mon, 28 Nov 2022 22:12:50 +0300 Subject: [PATCH] fix 1. remove call write_captured_output(report) from 'call' 2. add test --- src/_pytest/junitxml.py | 2 -- testing/test_junitxml.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py index d8884fe6d..2873ab8b4 100644 --- a/src/_pytest/junitxml.py +++ b/src/_pytest/junitxml.py @@ -560,8 +560,6 @@ class LogXML: if report.when == "call": # ignore setup/teardown reporter = self._opentestcase(report) reporter.append_pass(report) - if not self.log_passing_tests: - reporter.write_captured_output(report) elif report.failed: if report.when == "teardown": # The following vars are needed when xdist plugin is used. diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index b266c76d9..e63f7286b 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -932,6 +932,37 @@ class TestPython: assert "hello-stdout call" in systemout.toxml() assert "hello-stdout teardown" in systemout.toxml() + @pytest.mark.parametrize("junit_logging", ["no", "system-out"]) + def test_call_failed_stdout( + self, pytester: Pytester, run_and_parse: RunAndParse, junit_logging: str + ) -> None: + pytester.makepyfile( + """ + import sys + import pytest + + @pytest.fixture + def arg(request): + yield + sys.stdout.write('hello-stdout teardown') + raise ValueError() + def test_function(arg): + sys.stdout.write('hello-stdout call') + raise ValueError() + """ + ) + result, dom = run_and_parse("-o", "junit_logging=%s" % junit_logging) + node = dom.find_first_by_tag("testsuite") + pnode = node.find_first_by_tag("testcase") + if junit_logging == "no": + assert not node.find_by_tag( + "system-out" + ), "system-out should not be generated" + if junit_logging == "system-out": + systemout = pnode.find_first_by_tag("system-out") + assert systemout + assert "hello-stdout call" in systemout.toxml() + def test_mangle_test_address() -> None: from _pytest.junitxml import mangle_test_address