/usr/lib/imh-scan/venv/lib/python3.13/site-packages/_pytest
NameSizeModeActions
assertion/-0755rm
config/-0755rm
mark/-0755rm
_code/-0755rm
_io/-0755rm
_py/-0755rm
__pycache__/-0755rm
cacheprovider.py223750644editdlrm
capture.py368290644editdlrm
compat.py106620644editdlrm
debugging.py139470644editdlrm
deprecated.py31470644editdlrm
doctest.py262590644editdlrm
faulthandler.py36830644editdlrm
fixtures.py777460644editdlrm
freeze_support.py13000644editdlrm
helpconfig.py93860644editdlrm
hookspec.py428490644editdlrm
junitxml.py254410644editdlrm
legacypath.py165880644editdlrm
logging.py352340644editdlrm
main.py376890644editdlrm
monkeypatch.py146250644editdlrm
nodes.py265400644editdlrm
outcomes.py105020644editdlrm
pastebin.py41550644editdlrm
pathlib.py376220644editdlrm
py.typed00644editdlrm
pytester.py619600644editdlrm
pytester_assertions.py22530644editdlrm
python.py666270644editdlrm
python_api.py313230644editdlrm
raises.py601960644editdlrm
recwarn.py132450644editdlrm
reports.py214060644editdlrm
runner.py195430644editdlrm
scope.py27380644editdlrm
setuponly.py31670644editdlrm
setupplan.py11840644editdlrm
skipping.py106230644editdlrm
stash.py30900644editdlrm
stepwise.py76890644editdlrm
terminal.py604190644editdlrm
threadexception.py49530644editdlrm
timing.py30650644editdlrm
tmpdir.py112630644editdlrm
tracemalloc.py7780644editdlrm
unittest.py192490644editdlrm
unraisableexception.py51790644editdlrm
warnings.py52370644editdlrm
warning_types.py42390644editdlrm
_argcomplete.py37760644editdlrm
_version.py7040644editdlrm
__init__.py3910644editdlrm
Edit: /usr/lib/imh-scan/venv/lib/python3.13/site-packages/_pytest/faulthandler.py (3683B)
from __future__ import annotations from collections.abc import Generator import os import sys from _pytest.config import Config from _pytest.config.argparsing import Parser from _pytest.nodes import Item from _pytest.stash import StashKey import pytest fault_handler_original_stderr_fd_key = StashKey[int]() fault_handler_stderr_fd_key = StashKey[int]() def pytest_addoption(parser: Parser) -> None: help = ( "Dump the traceback of all threads if a test takes " "more than TIMEOUT seconds to finish" ) parser.addini("faulthandler_timeout", help, default=0.0) def pytest_configure(config: Config) -> None: import faulthandler # at teardown we want to restore the original faulthandler fileno # but faulthandler has no api to return the original fileno # so here we stash the stderr fileno to be used at teardown # 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 (#11572). stderr_fileno = get_stderr_fileno() if faulthandler.is_enabled(): config.stash[fault_handler_original_stderr_fd_key] = stderr_fileno config.stash[fault_handler_stderr_fd_key] = os.dup(stderr_fileno) faulthandler.enable(file=config.stash[fault_handler_stderr_fd_key]) def pytest_unconfigure(config: Config) -> None: import faulthandler faulthandler.disable() # Close the dup file installed during pytest_configure. if fault_handler_stderr_fd_key in config.stash: os.close(config.stash[fault_handler_stderr_fd_key]) del config.stash[fault_handler_stderr_fd_key] # Re-enable the faulthandler if it was originally enabled. if fault_handler_original_stderr_fd_key in config.stash: faulthandler.enable(config.stash[fault_handler_original_stderr_fd_key]) del config.stash[fault_handler_original_stderr_fd_key] def get_stderr_fileno() -> int: try: fileno = sys.stderr.fileno() # The Twisted Logger will return an invalid file descriptor since it is not backed # by an FD. So, let's also forward this to the same code path as with pytest-xdist. if fileno == -1: raise AttributeError() return fileno 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. assert sys.__stderr__ is not None return sys.__stderr__.fileno() def get_timeout_config_value(config: Config) -> float: return float(config.getini("faulthandler_timeout") or 0.0) @pytest.hookimpl(wrapper=True, trylast=True) def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]: timeout = get_timeout_config_value(item.config) if timeout > 0: import faulthandler stderr = item.config.stash[fault_handler_stderr_fd_key] faulthandler.dump_traceback_later(timeout, file=stderr) try: return (yield) finally: faulthandler.cancel_dump_traceback_later() else: return (yield) @pytest.hookimpl(tryfirst=True) def pytest_enter_pdb() -> None: """Cancel any traceback dumping due to timeout before entering pdb.""" import faulthandler faulthandler.cancel_dump_traceback_later() @pytest.hookimpl(tryfirst=True) def pytest_exception_interact() -> None: """Cancel any traceback dumping due to an interactive exception being raised.""" import faulthandler faulthandler.cancel_dump_traceback_later()