diff --git a/AUTHORS b/AUTHORS index 6d860575f37..be1e7863860 100644 --- a/AUTHORS +++ b/AUTHORS @@ -337,6 +337,7 @@ Serhii Mozghovyi Seth Junot Shantanu Jain Shubham Adep +Simon Blanchard Simon Gomizelj Simon Holesch Simon Kerr diff --git a/changelog/11439.bugfix.rst b/changelog/11439.bugfix.rst new file mode 100644 index 00000000000..b5104b1bcab --- /dev/null +++ b/changelog/11439.bugfix.rst @@ -0,0 +1 @@ +Handle an edge case where :data:`sys.stderr` might already be closed when :ref:`faulthandler` is tearing down. diff --git a/src/_pytest/faulthandler.py b/src/_pytest/faulthandler.py index af879aa44cf..36040bffffc 100644 --- a/src/_pytest/faulthandler.py +++ b/src/_pytest/faulthandler.py @@ -1,4 +1,3 @@ -import io import os import sys from typing import Generator @@ -51,7 +50,7 @@ def get_stderr_fileno() -> int: if fileno == -1: raise AttributeError() return fileno - except (AttributeError, io.UnsupportedOperation): + except (AttributeError, ValueError): # pytest-xdist monkeypatches sys.stderr with an object that is not an actual file. # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors # This is potentially dangerous, but the best we can do.