Merge pull request #554 from nicoddemus/fix-compat-pytest-master
This commit is contained in:
@@ -277,10 +277,17 @@ class DSession(object):
|
|||||||
self.config.hook.pytest_logwarning.call_historic(kwargs=kwargs)
|
self.config.hook.pytest_logwarning.call_historic(kwargs=kwargs)
|
||||||
|
|
||||||
def worker_warning_captured(self, warning_message, when, item):
|
def worker_warning_captured(self, warning_message, when, item):
|
||||||
"""Emitted when a node calls the pytest_logwarning hook."""
|
"""Emitted when a node calls the pytest_warning_captured hook (deprecated in 6.0)."""
|
||||||
kwargs = dict(warning_message=warning_message, when=when, item=item)
|
kwargs = dict(warning_message=warning_message, when=when, item=item)
|
||||||
self.config.hook.pytest_warning_captured.call_historic(kwargs=kwargs)
|
self.config.hook.pytest_warning_captured.call_historic(kwargs=kwargs)
|
||||||
|
|
||||||
|
def worker_warning_recorded(self, warning_message, when, nodeid, location):
|
||||||
|
"""Emitted when a node calls the pytest_warning_recorded hook."""
|
||||||
|
kwargs = dict(
|
||||||
|
warning_message=warning_message, when=when, nodeid=nodeid, location=location
|
||||||
|
)
|
||||||
|
self.config.hook.pytest_warning_recorded.call_historic(kwargs=kwargs)
|
||||||
|
|
||||||
def _clone_node(self, node):
|
def _clone_node(self, node):
|
||||||
"""Return new node based on an existing one.
|
"""Return new node based on an existing one.
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,18 @@ class WorkerInteractor(object):
|
|||||||
item=None,
|
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):
|
def serialize_warning_message(warning_message):
|
||||||
if isinstance(warning_message.message, Warning):
|
if isinstance(warning_message.message, Warning):
|
||||||
|
|||||||
@@ -359,6 +359,17 @@ class WorkerController(object):
|
|||||||
when=kwargs["when"],
|
when=kwargs["when"],
|
||||||
item=kwargs["item"],
|
item=kwargs["item"],
|
||||||
)
|
)
|
||||||
|
elif eventname == "warning_recorded":
|
||||||
|
warning_message = unserialize_warning_message(
|
||||||
|
kwargs["warning_message_data"]
|
||||||
|
)
|
||||||
|
self.notify_inproc(
|
||||||
|
eventname,
|
||||||
|
warning_message=warning_message,
|
||||||
|
when=kwargs["when"],
|
||||||
|
nodeid=kwargs["nodeid"],
|
||||||
|
location=kwargs["location"],
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError("unknown event: {}".format(eventname))
|
raise ValueError("unknown event: {}".format(eventname))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
@@ -22,12 +22,16 @@ def _divert_atexit(request, monkeypatch):
|
|||||||
|
|
||||||
finalizers = []
|
finalizers = []
|
||||||
|
|
||||||
def finish():
|
def fake_register(func, *args, **kwargs):
|
||||||
while finalizers:
|
finalizers.append((func, args, kwargs))
|
||||||
finalizers.pop()()
|
|
||||||
|
|
||||||
monkeypatch.setattr(atexit, "register", finalizers.append)
|
monkeypatch.setattr(atexit, "register", fake_register)
|
||||||
request.addfinalizer(finish)
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
while finalizers:
|
||||||
|
func, args, kwargs = finalizers.pop()
|
||||||
|
func(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
|
|||||||
Reference in New Issue
Block a user