Do not trigger pytest_warning_captured in pytest 6.0+

Fix #562
This commit is contained in:
Bruno Oliveira
2020-07-24 15:19:07 -03:00
parent 2fc21fddbb
commit 18b18870a8
3 changed files with 39 additions and 12 deletions

View File

@@ -139,18 +139,6 @@ class WorkerInteractor(object):
fslocation=str(fslocation),
)
# the pytest_warning_captured hook was introduced in pytest 3.8
if hasattr(_pytest.hookspec, "pytest_warning_captured"):
def pytest_warning_captured(self, warning_message, when, item):
self.sendevent(
"warning_captured",
warning_message_data=serialize_warning_message(warning_message),
when=when,
# item cannot be serialized and will always be None when used with xdist
item=None,
)
# the pytest_warning_recorded hook was introduced in pytest 6.0
if hasattr(_pytest.hookspec, "pytest_warning_recorded"):
@@ -163,6 +151,18 @@ class WorkerInteractor(object):
location=location,
)
# the pytest_warning_captured hook was introduced in pytest 3.8
elif hasattr(_pytest.hookspec, "pytest_warning_captured"):
def pytest_warning_captured(self, warning_message, when, item):
self.sendevent(
"warning_captured",
warning_message_data=serialize_warning_message(warning_message),
when=when,
# item cannot be serialized and will always be None when used with xdist
item=None,
)
def serialize_warning_message(warning_message):
if isinstance(warning_message.message, Warning):