From 9e81d88e5e9ac12cebc9848466560489b3064982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=C3=A9ta=20Cal=C3=A1bkov=C3=A1?= Date: Mon, 31 Aug 2020 15:50:54 +0200 Subject: [PATCH] Revert "Remove compat for pytest < 6" This reverts commit d153e0a4c4b764c821da9907ba3d2cac31bc3884. --- src/xdist/remote.py | 39 ++++++++++++++++++++++++++++---------- src/xdist/workermanage.py | 6 +++++- testing/acceptance_test.py | 2 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/xdist/remote.py b/src/xdist/remote.py index 26cf958..b78d744 100644 --- a/src/xdist/remote.py +++ b/src/xdist/remote.py @@ -11,6 +11,7 @@ import os import time import py +import _pytest.hookspec import pytest from execnet.gateway_base import dumps, DumpError @@ -100,8 +101,11 @@ class WorkerInteractor: def pytest_runtest_logstart(self, nodeid, location): self.sendevent("logstart", nodeid=nodeid, location=location) - def pytest_runtest_logfinish(self, nodeid, location): - self.sendevent("logfinish", nodeid=nodeid, location=location) + # the pytest_runtest_logfinish hook was introduced in pytest 3.4 + if hasattr(_pytest.hookspec, "pytest_runtest_logfinish"): + + def pytest_runtest_logfinish(self, nodeid, location): + self.sendevent("logfinish", nodeid=nodeid, location=location) def pytest_runtest_logreport(self, report): data = self.config.hook.pytest_report_to_serializable( @@ -121,14 +125,29 @@ class WorkerInteractor: ) self.sendevent("collectreport", data=data) - 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, - ) + # 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, + ) + + # 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): diff --git a/src/xdist/workermanage.py b/src/xdist/workermanage.py index 9b00251..141d86a 100644 --- a/src/xdist/workermanage.py +++ b/src/xdist/workermanage.py @@ -383,7 +383,11 @@ class WorkerController: except: # noqa from _pytest._code import ExceptionInfo - excinfo = ExceptionInfo.from_current() + # ExceptionInfo API changed in pytest 4.1 + if hasattr(ExceptionInfo, "from_current"): + excinfo = ExceptionInfo.from_current() + else: + excinfo = ExceptionInfo() print("!" * 20, excinfo) self.config.notify_exception(excinfo) self.shutdown() diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 8cac669..eee794c 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -1364,7 +1364,7 @@ def parse_tests_and_workers_from_output(lines): r""" \[(gw\d)\] # worker \s* - (?:\[\s*\d+%\])? # progress indicator + (?:\[\s*\d+%\])? # progress indicator (pytest >=3.3) \s(.*?) # status string ("PASSED") \s(.*::.*) # nodeid """, -- 2.28.0