/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/warnings.py (5237B)
# mypy: allow-untyped-defs from __future__ import annotations from collections.abc import Generator from contextlib import contextmanager from contextlib import ExitStack import sys from typing import Literal import warnings from _pytest.config import apply_warning_filters from _pytest.config import Config from _pytest.config import parse_warning_filter from _pytest.main import Session from _pytest.nodes import Item from _pytest.terminal import TerminalReporter from _pytest.tracemalloc import tracemalloc_message import pytest @contextmanager def catch_warnings_for_item( config: Config, ihook, when: Literal["config", "collect", "runtest"], item: Item | None, *, record: bool = True, ) -> Generator[None]: """Context manager that catches warnings generated in the contained execution block. ``item`` can be None if we are not in the context of an item execution. Each warning captured triggers the ``pytest_warning_recorded`` hook. """ config_filters = config.getini("filterwarnings") cmdline_filters = config.known_args_namespace.pythonwarnings or [] with warnings.catch_warnings(record=record) as log: if not sys.warnoptions: # If user is not explicitly configuring warning filters, show deprecation warnings by default (#2908). warnings.filterwarnings("always", category=DeprecationWarning) warnings.filterwarnings("always", category=PendingDeprecationWarning) # To be enabled in pytest 9.0.0. # warnings.filterwarnings("error", category=pytest.PytestRemovedIn9Warning) apply_warning_filters(config_filters, cmdline_filters) # apply filters from "filterwarnings" marks nodeid = "" if item is None else item.nodeid if item is not None: for mark in item.iter_markers(name="filterwarnings"): for arg in mark.args: warnings.filterwarnings(*parse_warning_filter(arg, escape=False)) try: yield finally: if record: # mypy can't infer that record=True means log is not None; help it. assert log is not None for warning_message in log: ihook.pytest_warning_recorded.call_historic( kwargs=dict( warning_message=warning_message, nodeid=nodeid, when=when, location=None, ) ) def warning_record_to_str(warning_message: warnings.WarningMessage) -> str: """Convert a warnings.WarningMessage to a string.""" return warnings.formatwarning( str(warning_message.message), warning_message.category, warning_message.filename, warning_message.lineno, warning_message.line, ) + tracemalloc_message(warning_message.source) @pytest.hookimpl(wrapper=True, tryfirst=True) def pytest_runtest_protocol(item: Item) -> Generator[None, object, object]: with catch_warnings_for_item( config=item.config, ihook=item.ihook, when="runtest", item=item ): return (yield) @pytest.hookimpl(wrapper=True, tryfirst=True) def pytest_collection(session: Session) -> Generator[None, object, object]: config = session.config with catch_warnings_for_item( config=config, ihook=config.hook, when="collect", item=None ): return (yield) @pytest.hookimpl(wrapper=True) def pytest_terminal_summary( terminalreporter: TerminalReporter, ) -> Generator[None]: config = terminalreporter.config with catch_warnings_for_item( config=config, ihook=config.hook, when="config", item=None ): return (yield) @pytest.hookimpl(wrapper=True) def pytest_sessionfinish(session: Session) -> Generator[None]: config = session.config with catch_warnings_for_item( config=config, ihook=config.hook, when="config", item=None ): return (yield) @pytest.hookimpl(wrapper=True) def pytest_load_initial_conftests( early_config: Config, ) -> Generator[None]: with catch_warnings_for_item( config=early_config, ihook=early_config.hook, when="config", item=None ): return (yield) def pytest_configure(config: Config) -> None: with ExitStack() as stack: stack.enter_context( catch_warnings_for_item( config=config, ihook=config.hook, when="config", item=None, # this disables recording because the terminalreporter has # finished by the time it comes to reporting logged warnings # from the end of config cleanup. So for now, this is only # useful for setting a warning filter with an 'error' action. record=False, ) ) config.addinivalue_line( "markers", "filterwarnings(warning): add a warning filter to the given test. " "see https://docs.pytest.org/en/stable/how-to/capture-warnings.html#pytest-mark-filterwarnings ", ) config.add_cleanup(stack.pop_all().close)