Support new `pytest_warning_recorded` hook from pytest 6.0

This commit is contained in:
Bruno Oliveira
2020-07-08 17:51:45 -03:00
parent 77a1db27cd
commit b25757199c
3 changed files with 31 additions and 1 deletions

View File

@@ -151,6 +151,18 @@ class WorkerInteractor(object):
item=None,
)
# the pytest_warning_recorded hook was introduced in pytest 6.0
if hasattr(_pytest.hookspec, "pytest_warning_recorded"):
def pytest_warning_recorded(self, warning_message, when, nodeid, location):
self.sendevent(
"warning_recorded",
warning_message_data=serialize_warning_message(warning_message),
when=when,
nodeid=nodeid,
location=location,
)
def serialize_warning_message(warning_message):
if isinstance(warning_message.message, Warning):