Remove deprecated `pytest_warning_captured` hook
This commit is contained in:
parent
0b0e2d2dbb
commit
41d8fb09ca
|
@ -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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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 <module>
|
||||
when the execution context is at the module level.
|
||||
"""
|
||||
|
||||
|
||||
@hookspec(historic=True)
|
||||
def pytest_warning_recorded(
|
||||
warning_message: "warnings.WarningMessage",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue