From 088d400b2da633c3eaa7e2b9b6edef18f88dd885 Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Sun, 24 May 2020 20:43:23 -0400 Subject: [PATCH] rename pytest_warning_record -> pytest_warning_recorded --- doc/en/reference.rst | 2 +- src/_pytest/hookspec.py | 4 ++-- src/_pytest/terminal.py | 4 ++-- src/_pytest/warnings.py | 8 ++++---- testing/test_warnings.py | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 13d2484bb..7348636a2 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -711,7 +711,7 @@ Session related reporting hooks: .. autofunction:: pytest_fixture_setup .. autofunction:: pytest_fixture_post_finalizer .. autofunction:: pytest_warning_captured -.. autofunction:: pytest_warning_record +.. autofunction:: pytest_warning_recorded Central hook for reporting about test execution: diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index c983f87f9..8ccb89ca5 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -625,7 +625,7 @@ def pytest_warning_captured(warning_message, when, item, location): """(**Deprecated**) Process a warning captured by the internal pytest warnings plugin. This hook is considered deprecated and will be removed in a future pytest version. - Use :func:`pytest_warning_record` instead. + 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 @@ -648,7 +648,7 @@ def pytest_warning_captured(warning_message, when, item, location): @hookspec(historic=True) -def pytest_warning_record(warning_message, when, nodeid, location): +def pytest_warning_recorded(warning_message, when, nodeid, location): """ Process a warning captured by the internal pytest warnings plugin. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 2524fb21f..10fb1f769 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -227,7 +227,7 @@ def pytest_report_teststatus(report: TestReport) -> Tuple[str, str, str]: @attr.s class WarningReport: """ - Simple structure to hold warnings information captured by ``pytest_warning_record``. + Simple structure to hold warnings information captured by ``pytest_warning_recorded``. :ivar str message: user friendly message about the warning :ivar str|None nodeid: node id that generated the warning (see ``get_location``). @@ -414,7 +414,7 @@ class TerminalReporter: def pytest_warning_captured(self, warning_message, item): pass - def pytest_warning_record(self, warning_message, nodeid): + def pytest_warning_recorded(self, warning_message, nodeid): from _pytest.warnings import warning_record_to_str fslocation = warning_message.filename, warning_message.lineno diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index 4aa2321aa..6d383ccdd 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -81,7 +81,7 @@ def catch_warnings_for_item(config, ihook, when, item): ``item`` can be None if we are not in the context of an item execution. - Each warning captured triggers the ``pytest_warning_record`` hook. + Each warning captured triggers the ``pytest_warning_recorded`` hook. """ cmdline_filters = config.getoption("pythonwarnings") or [] inifilters = config.getini("filterwarnings") @@ -111,7 +111,7 @@ def catch_warnings_for_item(config, ihook, when, item): yield for warning_message in log: - ihook.pytest_warning_record.call_historic( + ihook.pytest_warning_recorded.call_historic( kwargs=dict(warning_message=warning_message, nodeid=nodeid, when=when) ) @@ -167,7 +167,7 @@ def pytest_sessionfinish(session): def _issue_warning_captured(warning, hook, stacklevel): """ This function should be used instead of calling ``warnings.warn`` directly when we are in the "configure" stage: - at this point the actual options might not have been set, so we manually trigger the pytest_warning_record + at this point the actual options might not have been set, so we manually trigger the pytest_warning_recorded hook so we can display these warnings in the terminal. This is a hack until we can sort out #2891. :param warning: the warning instance. @@ -181,7 +181,7 @@ def _issue_warning_captured(warning, hook, stacklevel): assert records is not None frame = sys._getframe(stacklevel - 1) location = frame.f_code.co_filename, frame.f_lineno, frame.f_code.co_name - hook.pytest_warning_record.call_historic( + hook.pytest_warning_recorded.call_historic( kwargs=dict( warning_message=records[0], when="config", nodeid="", location=location ) diff --git a/testing/test_warnings.py b/testing/test_warnings.py index ec75e6571..6cfdfa6bb 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -268,7 +268,7 @@ def test_warning_captured_hook(testdir): collected = [] class WarningCollector: - def pytest_warning_record(self, warning_message, when, nodeid): + def pytest_warning_recorded(self, warning_message, when, nodeid): collected.append((str(warning_message.message), when, nodeid)) result = testdir.runpytest(plugins=[WarningCollector()]) @@ -648,7 +648,7 @@ class TestStackLevel: captured = [] @classmethod - def pytest_warning_record(cls, warning_message, when, nodeid, location): + def pytest_warning_recorded(cls, warning_message, when, nodeid, location): cls.captured.append((warning_message, location)) testdir.plugins = [CapturedWarnings()]