Skip to content

Commit 41d8fb0

Browse files
committed
Remove deprecated pytest_warning_captured hook
1 parent 0b0e2d2 commit 41d8fb0

File tree

7 files changed

+17
-72
lines changed

7 files changed

+17
-72
lines changed

doc/en/deprecations.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,6 @@ The ``yield_fixture`` function/decorator
250250
It has been so for a very long time, so can be search/replaced safely.
251251

252252

253-
The ``pytest_warning_captured`` hook
254-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
255-
256-
.. deprecated:: 6.0
257-
258-
This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``.
259-
260-
Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter
261-
by a ``nodeid`` parameter.
262-
263253
The ``pytest.collect`` module
264254
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265255

@@ -276,6 +266,19 @@ As stated in our :ref:`backwards-compatibility` policy, deprecated features are
276266
an appropriate period of deprecation has passed.
277267

278268

269+
The ``pytest_warning_captured`` hook
270+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
271+
272+
.. deprecated:: 6.0
273+
.. versionremoved:: 7.0
274+
275+
This hook has an `item` parameter which cannot be serialized by ``pytest-xdist``.
276+
277+
Use the ``pytest_warning_recored`` hook instead, which replaces the ``item`` parameter
278+
by a ``nodeid`` parameter.
279+
280+
281+
279282
The ``pytest._fillfuncargs`` function
280283
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281284

doc/en/reference/reference.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ Session related reporting hooks:
758758
.. autofunction:: pytest_terminal_summary
759759
.. autofunction:: pytest_fixture_setup
760760
.. autofunction:: pytest_fixture_post_finalizer
761-
.. autofunction:: pytest_warning_captured
762761
.. autofunction:: pytest_warning_recorded
763762

764763
Central hook for reporting about test execution:

src/_pytest/config/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,14 +1330,6 @@ def issue_config_time_warning(self, warning: Warning, stacklevel: int) -> None:
13301330
if records:
13311331
frame = sys._getframe(stacklevel - 1)
13321332
location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name
1333-
self.hook.pytest_warning_captured.call_historic(
1334-
kwargs=dict(
1335-
warning_message=records[0],
1336-
when="config",
1337-
item=None,
1338-
location=location,
1339-
)
1340-
)
13411333
self.hook.pytest_warning_recorded.call_historic(
13421334
kwargs=dict(
13431335
warning_message=records[0],

src/_pytest/deprecated.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@
4646
"Please open an issue if you use this and want a replacement."
4747
)
4848

49-
WARNING_CAPTURED_HOOK = PytestRemovedIn7Warning(
50-
"The pytest_warning_captured is deprecated and will be removed in a future release.\n"
51-
"Please use pytest_warning_recorded instead."
52-
)
53-
5449
WARNING_CMDLINE_PREPARSE_HOOK = PytestRemovedIn8Warning(
5550
"The pytest_cmdline_preparse hook is deprecated and will be removed in a future release. \n"
5651
"Please use pytest_load_initial_conftests hook instead."

src/_pytest/hookspec.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from pluggy import HookspecMarker
1515

16-
from _pytest.deprecated import WARNING_CAPTURED_HOOK
1716
from _pytest.deprecated import WARNING_CMDLINE_PREPARSE_HOOK
1817

1918
if TYPE_CHECKING:
@@ -777,41 +776,6 @@ def pytest_terminal_summary(
777776
"""
778777

779778

780-
@hookspec(historic=True, warn_on_impl=WARNING_CAPTURED_HOOK)
781-
def pytest_warning_captured(
782-
warning_message: "warnings.WarningMessage",
783-
when: "Literal['config', 'collect', 'runtest']",
784-
item: Optional["Item"],
785-
location: Optional[Tuple[str, int, str]],
786-
) -> None:
787-
"""(**Deprecated**) Process a warning captured by the internal pytest warnings plugin.
788-
789-
.. deprecated:: 6.0
790-
791-
This hook is considered deprecated and will be removed in a future pytest version.
792-
Use :func:`pytest_warning_recorded` instead.
793-
794-
:param warnings.WarningMessage warning_message:
795-
The captured warning. This is the same object produced by :py:func:`warnings.catch_warnings`, and contains
796-
the same attributes as the parameters of :py:func:`warnings.showwarning`.
797-
798-
:param str when:
799-
Indicates when the warning was captured. Possible values:
800-
801-
* ``"config"``: during pytest configuration/initialization stage.
802-
* ``"collect"``: during test collection.
803-
* ``"runtest"``: during test execution.
804-
805-
:param pytest.Item|None item:
806-
The item being executed if ``when`` is ``"runtest"``, otherwise ``None``.
807-
808-
:param tuple location:
809-
When available, holds information about the execution context of the captured
810-
warning (filename, linenumber, function). ``function`` evaluates to <module>
811-
when the execution context is at the module level.
812-
"""
813-
814-
815779
@hookspec(historic=True)
816780
def pytest_warning_recorded(
817781
warning_message: "warnings.WarningMessage",

src/_pytest/warnings.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ def catch_warnings_for_item(
6363
yield
6464

6565
for warning_message in log:
66-
ihook.pytest_warning_captured.call_historic(
67-
kwargs=dict(
68-
warning_message=warning_message,
69-
when=when,
70-
item=item,
71-
location=None,
72-
)
73-
)
7466
ihook.pytest_warning_recorded.call_historic(
7567
kwargs=dict(
7668
warning_message=warning_message,

testing/test_warnings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_func():
239239

240240

241241
@pytest.mark.filterwarnings("always::UserWarning")
242-
def test_warning_captured_hook(pytester: Pytester) -> None:
242+
def test_warning_recorded_hook(pytester: Pytester) -> None:
243243
pytester.makeconftest(
244244
"""
245245
def pytest_configure(config):
@@ -276,9 +276,9 @@ def pytest_warning_recorded(self, warning_message, when, nodeid, location):
276276
expected = [
277277
("config warning", "config", ""),
278278
("collect warning", "collect", ""),
279-
("setup warning", "runtest", "test_warning_captured_hook.py::test_func"),
280-
("call warning", "runtest", "test_warning_captured_hook.py::test_func"),
281-
("teardown warning", "runtest", "test_warning_captured_hook.py::test_func"),
279+
("setup warning", "runtest", "test_warning_recorded_hook.py::test_func"),
280+
("call warning", "runtest", "test_warning_recorded_hook.py::test_func"),
281+
("teardown warning", "runtest", "test_warning_recorded_hook.py::test_func"),
282282
]
283283
for index in range(len(expected)):
284284
collected_result = collected[index]

0 commit comments

Comments
 (0)