diff --git a/changelog/13695.contrib.rst b/changelog/13695.contrib.rst new file mode 100644 index 00000000000..675e1fc96a0 --- /dev/null +++ b/changelog/13695.contrib.rst @@ -0,0 +1 @@ +Flush `stdout` and `stderr` in `Pytester.run` to avoid truncated outputs in `test_faulthandler.py::test_timeout` on CI -- by :user:`ogrisel`. diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index de4e2c8b136..d5b67abdaee 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -1422,7 +1422,6 @@ def run( stdin=stdin, stdout=f1, stderr=f2, - close_fds=(sys.platform != "win32"), ) if popen.stdin is not None: popen.stdin.close() @@ -1443,6 +1442,8 @@ def handle_timeout() -> None: ret = popen.wait(timeout) except subprocess.TimeoutExpired: handle_timeout() + f1.flush() + f2.flush() with p1.open(encoding="utf8") as f1, p2.open(encoding="utf8") as f2: out = f1.read().splitlines() diff --git a/testing/test_faulthandler.py b/testing/test_faulthandler.py index d89cb274b78..b308e89adbd 100644 --- a/testing/test_faulthandler.py +++ b/testing/test_faulthandler.py @@ -2,6 +2,7 @@ from __future__ import annotations import io +import os import sys from _pytest.pytester import Pytester @@ -76,7 +77,13 @@ def test_disabled(): "enabled", [ pytest.param( - True, marks=pytest.mark.skip(reason="sometimes crashes on CI (#7022)") + True, + marks=pytest.mark.skipif( + "CI" in os.environ + and sys.platform == "linux" + and sys.version_info >= (3, 14), + reason="sometimes crashes on CI because of truncated outputs (#7022)", + ), ), False, ], diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 8c50311e9aa..2a3f4446a11 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -2250,8 +2250,8 @@ def test_times_multiline( output.stdout.re_match_lines( [ r"test_bar.py ...................", - r"........... \s+ \d{1,3}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$", - r"test_foo.py \.{5} \s+ \d{1,3}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$", + r"........... \s+ \d{1,4}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$", + r"test_foo.py \.{5} \s+ \d{1,4}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$", ], consecutive=True, )