Skip to content

Commit a38ad25

Browse files
authored
Handle ValueError raised during faulthandler teardown code (#11453)
Fixes #11439
1 parent 9f22d32 commit a38ad25

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ Seth Junot
347347
Shantanu Jain
348348
Sharad Nair
349349
Shubham Adep
350+
Simon Blanchard
350351
Simon Gomizelj
351352
Simon Holesch
352353
Simon Kerr

changelog/11439.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle an edge case where :data:`sys.stderr` might already be closed when :ref:`faulthandler` is tearing down.

src/_pytest/faulthandler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import io
21
import os
32
import sys
43
from typing import Generator
@@ -51,7 +50,7 @@ def get_stderr_fileno() -> int:
5150
if fileno == -1:
5251
raise AttributeError()
5352
return fileno
54-
except (AttributeError, io.UnsupportedOperation):
53+
except (AttributeError, ValueError):
5554
# pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
5655
# https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
5756
# This is potentially dangerous, but the best we can do.

0 commit comments

Comments
 (0)