Skip to content

Commit 6ab228b

Browse files
authored
Flush stdout and stderr in pytester.run (pytest-dev#13695)
Attempted to make `test_faulthandler.py::test_timeout` more reliable on CI, but ultimately this was not accomplished. However, it seems flushing `stdout` and `stderr` during `pytester.run` seems the right thing to do, so it was decided to leave the calls and only skip the test in more specific scenarios that were failing frequently on CI (see pytest-dev#13695 for discussion history). We should extend the skip list as needed. Follow-up on pytest-dev#13684. Partially addresses pytest-dev#7022.
1 parent 41ffbef commit 6ab228b

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

changelog/13695.contrib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flush `stdout` and `stderr` in `Pytester.run` to avoid truncated outputs in `test_faulthandler.py::test_timeout` on CI -- by :user:`ogrisel`.

src/_pytest/pytester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ def run(
14221422
stdin=stdin,
14231423
stdout=f1,
14241424
stderr=f2,
1425-
close_fds=(sys.platform != "win32"),
14261425
)
14271426
if popen.stdin is not None:
14281427
popen.stdin.close()
@@ -1443,6 +1442,8 @@ def handle_timeout() -> None:
14431442
ret = popen.wait(timeout)
14441443
except subprocess.TimeoutExpired:
14451444
handle_timeout()
1445+
f1.flush()
1446+
f2.flush()
14461447

14471448
with p1.open(encoding="utf8") as f1, p2.open(encoding="utf8") as f2:
14481449
out = f1.read().splitlines()

testing/test_faulthandler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
import io
5+
import os
56
import sys
67

78
from _pytest.pytester import Pytester
@@ -76,7 +77,13 @@ def test_disabled():
7677
"enabled",
7778
[
7879
pytest.param(
79-
True, marks=pytest.mark.skip(reason="sometimes crashes on CI (#7022)")
80+
True,
81+
marks=pytest.mark.skipif(
82+
"CI" in os.environ
83+
and sys.platform == "linux"
84+
and sys.version_info >= (3, 14),
85+
reason="sometimes crashes on CI because of truncated outputs (#7022)",
86+
),
8087
),
8188
False,
8289
],

testing/test_terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,8 +2250,8 @@ def test_times_multiline(
22502250
output.stdout.re_match_lines(
22512251
[
22522252
r"test_bar.py ...................",
2253-
r"........... \s+ \d{1,3}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$",
2254-
r"test_foo.py \.{5} \s+ \d{1,3}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$",
2253+
r"........... \s+ \d{1,4}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$",
2254+
r"test_foo.py \.{5} \s+ \d{1,4}[\.[a-z\ ]{1,2}\d{0,3}\w{1,2}$",
22552255
],
22562256
consecutive=True,
22572257
)

0 commit comments

Comments
 (0)