Revert to having just "runtest" as "when" parameter of the pytest_warning_captured hook

This commit is contained in:
Bruno Oliveira 2018-09-04 17:01:23 -03:00
parent 5a52acaa92
commit 2e0a7cf78d
3 changed files with 7 additions and 26 deletions

View File

@ -559,13 +559,10 @@ def pytest_warning_captured(warning_message, when, item):
* ``"config"``: during pytest configuration/initialization stage. * ``"config"``: during pytest configuration/initialization stage.
* ``"collect"``: during test collection. * ``"collect"``: during test collection.
* ``"setup"``: during test setup. * ``"runtest"``: during test execution.
* ``"call"``: during test call.
* ``"teardown"``: during test teardown.
:param pytest.Item|None item: :param pytest.Item|None item:
The item being executed if ``when`` is ``"setup"``, ``"call"`` or ``"teardown"``, otherwise The item being executed if ``when`` is ``"runtest"``, otherwise ``None``.
``None``.
""" """

View File

@ -130,25 +130,9 @@ def warning_record_to_str(warning_message):
@pytest.hookimpl(hookwrapper=True, tryfirst=True) @pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_setup(item): def pytest_runtest_protocol(item):
with catch_warnings_for_item( with catch_warnings_for_item(
config=item.config, ihook=item.ihook, when="setup", item=item config=item.config, ihook=item.ihook, when="runtest", 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
): ):
yield yield

View File

@ -341,9 +341,9 @@ def test_warning_captured_hook(testdir):
expected = [ expected = [
("config warning", "config", ""), ("config warning", "config", ""),
("collect warning", "collect", ""), ("collect warning", "collect", ""),
("setup warning", "setup", "test_func"), ("setup warning", "runtest", "test_func"),
("call warning", "call", "test_func"), ("call warning", "runtest", "test_func"),
("teardown warning", "teardown", "test_func"), ("teardown warning", "runtest", "test_func"),
] ]
assert collected == expected assert collected == expected