From 6bd3d8404d24f3ecf4f216cbce4029aba8f90de8 Mon Sep 17 00:00:00 2001 From: Simon Blanchard Date: Sun, 5 Nov 2023 13:42:49 +0100 Subject: [PATCH] add comment about why we're stashing stderr fileno --- src/_pytest/faulthandler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/_pytest/faulthandler.py b/src/_pytest/faulthandler.py index 7780ad5e9..dd8177bae 100644 --- a/src/_pytest/faulthandler.py +++ b/src/_pytest/faulthandler.py @@ -25,6 +25,9 @@ def pytest_addoption(parser: Parser) -> None: def pytest_configure(config: Config) -> None: import faulthandler + # stash original stderr fileno to be restored at the end of the test session + # sys.stderr and sys.__stderr__ may be closed or patched during the session + # so we can't rely on their values being good at that point stderr_fileno = get_stderr_fileno() config.stash[fault_handler_original_stderr_fd_key] = stderr_fileno config.stash[fault_handler_stderr_fd_key] = os.dup(stderr_fileno)