From 125b663f20a599e7e39fce821597a122d62a6460 Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Mon, 25 May 2020 11:18:24 -0400 Subject: [PATCH] Address all feedback, minus the empty sring v None nodeid which is being discussed --- src/_pytest/hookspec.py | 7 ++++++- src/_pytest/terminal.py | 3 --- src/_pytest/warnings.py | 8 ++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 8ccb89ca5..e2810ec78 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -620,7 +620,12 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config): """ -@hookspec(historic=True) +@hookspec( + historic=True, + warn_on_impl=DeprecationWarning( + "pytest_warning_captured is deprecated and will be removed soon" + ), +) def pytest_warning_captured(warning_message, when, item, location): """(**Deprecated**) Process a warning captured by the internal pytest warnings plugin. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 10fb1f769..d26db2c51 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -411,9 +411,6 @@ class TerminalReporter: self.write_line("INTERNALERROR> " + line) return 1 - def pytest_warning_captured(self, warning_message, item): - pass - def pytest_warning_recorded(self, warning_message, nodeid): from _pytest.warnings import warning_record_to_str diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index 6d383ccdd..3ae3c8639 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -111,6 +111,9 @@ def catch_warnings_for_item(config, ihook, when, item): yield for warning_message in log: + ihook.pytest_warning_captured.call_historic( + kwargs=dict(warning_message=warning_message, when=when, item=item) + ) ihook.pytest_warning_recorded.call_historic( kwargs=dict(warning_message=warning_message, nodeid=nodeid, when=when) ) @@ -181,6 +184,11 @@ 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_captured.call_historic( + kwargs=dict( + warning_message=records[0], when="config", item=None, location=location + ) + ) hook.pytest_warning_recorded.call_historic( kwargs=dict( warning_message=records[0], when="config", nodeid="", location=location