Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with pytest master #554

Merged
merged 2 commits into from Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/xdist/dsession.py
Expand Up @@ -277,10 +277,17 @@ def worker_logwarning(self, message, code, nodeid, fslocation):
self.config.hook.pytest_logwarning.call_historic(kwargs=kwargs)

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)
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):
"""Return new node based on an existing one.

Expand Down
12 changes: 12 additions & 0 deletions src/xdist/remote.py
Expand Up @@ -151,6 +151,18 @@ def pytest_warning_captured(self, warning_message, when, item):
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):
Expand Down
11 changes: 11 additions & 0 deletions src/xdist/workermanage.py
Expand Up @@ -359,6 +359,17 @@ def process_from_remote(self, eventcall): # noqa too complex
when=kwargs["when"],
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:
raise ValueError("unknown event: {}".format(eventname))
except KeyboardInterrupt:
Expand Down
14 changes: 9 additions & 5 deletions testing/conftest.py
Expand Up @@ -22,12 +22,16 @@ def _divert_atexit(request, monkeypatch):

finalizers = []

def finish():
while finalizers:
finalizers.pop()()
def fake_register(func, *args, **kwargs):
finalizers.append((func, args, kwargs))

monkeypatch.setattr(atexit, "register", finalizers.append)
request.addfinalizer(finish)
monkeypatch.setattr(atexit, "register", fake_register)

yield

while finalizers:
func, args, kwargs = finalizers.pop()
func(*args, **kwargs)


def pytest_addoption(parser):
Expand Down