aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest/py3/_pytest/warnings.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-05-05 12:31:52 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-05-05 12:41:33 +0300
commit6ff49ec58061f642c3a2f83c61eba12820787dfc (patch)
treec733ec9bdb15ed280080d31dea8725bfec717acd /contrib/python/pytest/py3/_pytest/warnings.py
parenteefca8305c6a545cc6b16dca3eb0d91dcef2adcd (diff)
downloadydb-6ff49ec58061f642c3a2f83c61eba12820787dfc.tar.gz
Intermediate changes
commit_hash:8b3bb826b17db8329ed1221f545c0645f12c552d
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/warnings.py')
-rw-r--r--contrib/python/pytest/py3/_pytest/warnings.py60
1 files changed, 30 insertions, 30 deletions
diff --git a/contrib/python/pytest/py3/_pytest/warnings.py b/contrib/python/pytest/py3/_pytest/warnings.py
index 4aaa9445293..f45163fa2e6 100644
--- a/contrib/python/pytest/py3/_pytest/warnings.py
+++ b/contrib/python/pytest/py3/_pytest/warnings.py
@@ -1,20 +1,17 @@
-import sys
-import warnings
from contextlib import contextmanager
+import sys
from typing import Generator
+from typing import Literal
from typing import Optional
-from typing import TYPE_CHECKING
+import warnings
-import pytest
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
-
-if TYPE_CHECKING:
- from typing_extensions import Literal
+import pytest
def pytest_configure(config: Config) -> None:
@@ -29,7 +26,7 @@ def pytest_configure(config: Config) -> None:
def catch_warnings_for_item(
config: Config,
ihook,
- when: "Literal['config', 'collect', 'runtest']",
+ when: Literal["config", "collect", "runtest"],
item: Optional[Item],
) -> Generator[None, None, None]:
"""Context manager that catches warnings generated in the contained execution block.
@@ -49,6 +46,8 @@ def catch_warnings_for_item(
warnings.filterwarnings("always", category=DeprecationWarning)
warnings.filterwarnings("always", category=PendingDeprecationWarning)
+ warnings.filterwarnings("error", category=pytest.PytestRemovedIn8Warning)
+
apply_warning_filters(config_filters, cmdline_filters)
# apply filters from "filterwarnings" marks
@@ -58,17 +57,18 @@ def catch_warnings_for_item(
for arg in mark.args:
warnings.filterwarnings(*parse_warning_filter(arg, escape=False))
- yield
-
- for warning_message in log:
- ihook.pytest_warning_recorded.call_historic(
- kwargs=dict(
- warning_message=warning_message,
- nodeid=nodeid,
- when=when,
- location=None,
+ try:
+ yield
+ finally:
+ 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:
@@ -101,24 +101,24 @@ def warning_record_to_str(warning_message: warnings.WarningMessage) -> str:
return msg
-@pytest.hookimpl(hookwrapper=True, tryfirst=True)
-def pytest_runtest_protocol(item: Item) -> Generator[None, None, None]:
+@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
):
- yield
+ return (yield)
-@pytest.hookimpl(hookwrapper=True, tryfirst=True)
-def pytest_collection(session: Session) -> Generator[None, None, None]:
+@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
):
- yield
+ return (yield)
-@pytest.hookimpl(hookwrapper=True)
+@pytest.hookimpl(wrapper=True)
def pytest_terminal_summary(
terminalreporter: TerminalReporter,
) -> Generator[None, None, None]:
@@ -126,23 +126,23 @@ def pytest_terminal_summary(
with catch_warnings_for_item(
config=config, ihook=config.hook, when="config", item=None
):
- yield
+ return (yield)
-@pytest.hookimpl(hookwrapper=True)
+@pytest.hookimpl(wrapper=True)
def pytest_sessionfinish(session: Session) -> Generator[None, None, None]:
config = session.config
with catch_warnings_for_item(
config=config, ihook=config.hook, when="config", item=None
):
- yield
+ return (yield)
-@pytest.hookimpl(hookwrapper=True)
+@pytest.hookimpl(wrapper=True)
def pytest_load_initial_conftests(
early_config: "Config",
) -> Generator[None, None, None]:
with catch_warnings_for_item(
config=early_config, ihook=early_config.hook, when="config", item=None
):
- yield
+ return (yield)