From 41d8fb09ca1d201ef126347c4bffe77f0e0245d2 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 7 Dec 2021 22:00:31 +0200 Subject: [PATCH] Remove deprecated `pytest_warning_captured` hook --- doc/en/deprecations.rst | 23 ++++++++++++---------- doc/en/reference/reference.rst | 1 - src/_pytest/config/__init__.py | 8 -------- src/_pytest/deprecated.py | 5 ----- src/_pytest/hookspec.py | 36 ---------------------------------- src/_pytest/warnings.py | 8 -------- testing/test_warnings.py | 8 ++++---- 7 files changed, 17 insertions(+), 72 deletions(-) diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index c0f32c3bc..a966e6efc 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -250,16 +250,6 @@ The ``yield_fixture`` function/decorator It has been so for a very long time, so can be search/replaced safely. -The ``pytest_warning_captured`` hook -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. deprecated:: 6.0 - -This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``. - -Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter -by a ``nodeid`` parameter. - The ``pytest.collect`` module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -276,6 +266,19 @@ As stated in our :ref:`backwards-compatibility` policy, deprecated features are an appropriate period of deprecation has passed. +The ``pytest_warning_captured`` hook +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 6.0 +.. versionremoved:: 7.0 + +This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``. + +Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter +by a ``nodeid`` parameter. + + + The ``pytest._fillfuncargs`` function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index 8f6f2ce7c..c132ae6d3 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -758,7 +758,6 @@ Session related reporting hooks: .. autofunction:: pytest_terminal_summary .. autofunction:: pytest_fixture_setup .. autofunction:: pytest_fixture_post_finalizer -.. autofunction:: pytest_warning_captured .. autofunction:: pytest_warning_recorded Central hook for reporting about test execution: diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index eadce78fa..4cb22009a 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1330,14 +1330,6 @@ class Config: if records: frame = sys._getframe(stacklevel - 1) location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name - self.hook.pytest_warning_captured.call_historic( - kwargs=dict( - warning_message=records[0], - when="config", - item=None, - location=location, - ) - ) self.hook.pytest_warning_recorded.call_historic( kwargs=dict( warning_message=records[0], diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 88114fbf3..0d0af725e 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -46,11 +46,6 @@ MINUS_K_COLON = PytestRemovedIn7Warning( "Please open an issue if you use this and want a replacement." ) -WARNING_CAPTURED_HOOK = PytestRemovedIn7Warning( - "The pytest_warning_captured is deprecated and will be removed in a future release.\n" - "Please use pytest_warning_recorded instead." -) - WARNING_CMDLINE_PREPARSE_HOOK = PytestRemovedIn8Warning( "The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n" "Please use pytest_load_initial_conftests hook instead." diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index b65be9815..57f199499 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -13,7 +13,6 @@ from typing import Union from pluggy import HookspecMarker -from _pytest.deprecated import WARNING_CAPTURED_HOOK from _pytest.deprecated import WARNING_CMDLINE_PREPARSE_HOOK if TYPE_CHECKING: @@ -777,41 +776,6 @@ def pytest_terminal_summary( """ -@hookspec(historic=True, warn_on_impl=WARNING_CAPTURED_HOOK) -def pytest_warning_captured( - warning_message: "warnings.WarningMessage", - when: "Literal['config', 'collect', 'runtest']", - item: Optional["Item"], - location: Optional[Tuple[str, int, str]], -) -> None: - """(**Deprecated**) Process a warning captured by the internal pytest warnings plugin. - - .. deprecated:: 6.0 - - This hook is considered deprecated and will be removed in a future pytest version. - Use :func:`pytest_warning_recorded` instead. - - :param warnings.WarningMessage warning_message: - The captured warning. This is the same object produced by :py:func:`warnings.catch_warnings`, and contains - the same attributes as the parameters of :py:func:`warnings.showwarning`. - - :param str when: - Indicates when the warning was captured. Possible values: - - * ``"config"``: during pytest configuration/initialization stage. - * ``"collect"``: during test collection. - * ``"runtest"``: during test execution. - - :param pytest.Item|None item: - The item being executed if ``when`` is ``"runtest"``, otherwise ``None``. - - :param tuple location: - When available, holds information about the execution context of the captured - warning (filename, linenumber, function). ``function`` evaluates to - when the execution context is at the module level. - """ - - @hookspec(historic=True) def pytest_warning_recorded( warning_message: "warnings.WarningMessage", diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index c0c946cbd..d5afbfeb6 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -63,14 +63,6 @@ def catch_warnings_for_item( yield for warning_message in log: - ihook.pytest_warning_captured.call_historic( - kwargs=dict( - warning_message=warning_message, - when=when, - item=item, - location=None, - ) - ) ihook.pytest_warning_recorded.call_historic( kwargs=dict( warning_message=warning_message, diff --git a/testing/test_warnings.py b/testing/test_warnings.py index cac716680..45acb720d 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -239,7 +239,7 @@ def test_filterwarnings_mark_registration(pytester: Pytester) -> None: @pytest.mark.filterwarnings("always::UserWarning") -def test_warning_captured_hook(pytester: Pytester) -> None: +def test_warning_recorded_hook(pytester: Pytester) -> None: pytester.makeconftest( """ def pytest_configure(config): @@ -276,9 +276,9 @@ def test_warning_captured_hook(pytester: Pytester) -> None: expected = [ ("config warning", "config", ""), ("collect warning", "collect", ""), - ("setup warning", "runtest", "test_warning_captured_hook.py::test_func"), - ("call warning", "runtest", "test_warning_captured_hook.py::test_func"), - ("teardown warning", "runtest", "test_warning_captured_hook.py::test_func"), + ("setup warning", "runtest", "test_warning_recorded_hook.py::test_func"), + ("call warning", "runtest", "test_warning_recorded_hook.py::test_func"), + ("teardown warning", "runtest", "test_warning_recorded_hook.py::test_func"), ] for index in range(len(expected)): collected_result = collected[index]