diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 3e647d1a1..1a9326149 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -559,13 +559,10 @@ def pytest_warning_captured(warning_message, when, item): * ``"config"``: during pytest configuration/initialization stage. * ``"collect"``: during test collection. - * ``"setup"``: during test setup. - * ``"call"``: during test call. - * ``"teardown"``: during test teardown. + * ``"runtest"``: during test execution. :param pytest.Item|None item: - The item being executed if ``when`` is ``"setup"``, ``"call"`` or ``"teardown"``, otherwise - ``None``. + The item being executed if ``when`` is ``"runtest"``, otherwise ``None``. """ diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index e0206883a..770d6b2a6 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -130,25 +130,9 @@ def warning_record_to_str(warning_message): @pytest.hookimpl(hookwrapper=True, tryfirst=True) -def pytest_runtest_setup(item): +def pytest_runtest_protocol(item): with catch_warnings_for_item( - config=item.config, ihook=item.ihook, when="setup", item=item - ): - yield - - -@pytest.hookimpl(hookwrapper=True, tryfirst=True) -def pytest_runtest_call(item): - with catch_warnings_for_item( - config=item.config, ihook=item.ihook, when="call", item=item - ): - yield - - -@pytest.hookimpl(hookwrapper=True, tryfirst=True) -def pytest_runtest_teardown(item): - with catch_warnings_for_item( - config=item.config, ihook=item.ihook, when="teardown", item=item + config=item.config, ihook=item.ihook, when="runtest", item=item ): yield diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 119b67cee..11ca1e8f4 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -341,9 +341,9 @@ def test_warning_captured_hook(testdir): expected = [ ("config warning", "config", ""), ("collect warning", "collect", ""), - ("setup warning", "setup", "test_func"), - ("call warning", "call", "test_func"), - ("teardown warning", "teardown", "test_func"), + ("setup warning", "runtest", "test_func"), + ("call warning", "runtest", "test_func"), + ("teardown warning", "runtest", "test_func"), ] assert collected == expected