Remove deprecated `pytest_warning_captured` hook

This commit is contained in:
Ran Benita 2021-12-07 22:00:31 +02:00
parent 0b0e2d2dbb
commit 41d8fb09ca
7 changed files with 17 additions and 72 deletions

View File

@ -250,16 +250,6 @@ The ``yield_fixture`` function/decorator
It has been so for a very long time, so can be search/replaced safely. 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 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. 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 The ``pytest._fillfuncargs`` function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -758,7 +758,6 @@ Session related reporting hooks:
.. autofunction:: pytest_terminal_summary .. autofunction:: pytest_terminal_summary
.. autofunction:: pytest_fixture_setup .. autofunction:: pytest_fixture_setup
.. autofunction:: pytest_fixture_post_finalizer .. autofunction:: pytest_fixture_post_finalizer
.. autofunction:: pytest_warning_captured
.. autofunction:: pytest_warning_recorded .. autofunction:: pytest_warning_recorded
Central hook for reporting about test execution: Central hook for reporting about test execution:

View File

@ -1330,14 +1330,6 @@ class Config:
if records: if records:
frame = sys._getframe(stacklevel - 1) frame = sys._getframe(stacklevel - 1)
location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name 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( self.hook.pytest_warning_recorded.call_historic(
kwargs=dict( kwargs=dict(
warning_message=records[0], warning_message=records[0],

View File

@ -46,11 +46,6 @@ MINUS_K_COLON = PytestRemovedIn7Warning(
"Please open an issue if you use this and want a replacement." "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( WARNING_CMDLINE_PREPARSE_HOOK = PytestRemovedIn8Warning(
"The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n" "The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n"
"Please use pytest_load_initial_conftests hook instead." "Please use pytest_load_initial_conftests hook instead."

View File

@ -13,7 +13,6 @@ from typing import Union
from pluggy import HookspecMarker from pluggy import HookspecMarker
from _pytest.deprecated import WARNING_CAPTURED_HOOK
from _pytest.deprecated import WARNING_CMDLINE_PREPARSE_HOOK from _pytest.deprecated import WARNING_CMDLINE_PREPARSE_HOOK
if TYPE_CHECKING: 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 <module>
when the execution context is at the module level.
"""
@hookspec(historic=True) @hookspec(historic=True)
def pytest_warning_recorded( def pytest_warning_recorded(
warning_message: "warnings.WarningMessage", warning_message: "warnings.WarningMessage",

View File

@ -63,14 +63,6 @@ def catch_warnings_for_item(
yield yield
for warning_message in log: 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( ihook.pytest_warning_recorded.call_historic(
kwargs=dict( kwargs=dict(
warning_message=warning_message, warning_message=warning_message,

View File

@ -239,7 +239,7 @@ def test_filterwarnings_mark_registration(pytester: Pytester) -> None:
@pytest.mark.filterwarnings("always::UserWarning") @pytest.mark.filterwarnings("always::UserWarning")
def test_warning_captured_hook(pytester: Pytester) -> None: def test_warning_recorded_hook(pytester: Pytester) -> None:
pytester.makeconftest( pytester.makeconftest(
""" """
def pytest_configure(config): def pytest_configure(config):
@ -276,9 +276,9 @@ def test_warning_captured_hook(pytester: Pytester) -> None:
expected = [ expected = [
("config warning", "config", ""), ("config warning", "config", ""),
("collect warning", "collect", ""), ("collect warning", "collect", ""),
("setup warning", "runtest", "test_warning_captured_hook.py::test_func"), ("setup warning", "runtest", "test_warning_recorded_hook.py::test_func"),
("call warning", "runtest", "test_warning_captured_hook.py::test_func"), ("call warning", "runtest", "test_warning_recorded_hook.py::test_func"),
("teardown warning", "runtest", "test_warning_captured_hook.py::test_func"), ("teardown warning", "runtest", "test_warning_recorded_hook.py::test_func"),
] ]
for index in range(len(expected)): for index in range(len(expected)):
collected_result = collected[index] collected_result = collected[index]