Remove compat for pytest < 6

This commit is contained in:
Zac-HD
2020-08-06 15:44:56 +10:00
parent ba8398478e
commit d153e0a4c4
3 changed files with 12 additions and 35 deletions

View File

@@ -11,7 +11,6 @@ import os
import time import time
import py import py
import _pytest.hookspec
import pytest import pytest
from execnet.gateway_base import dumps, DumpError from execnet.gateway_base import dumps, DumpError
@@ -101,11 +100,8 @@ class WorkerInteractor:
def pytest_runtest_logstart(self, nodeid, location): def pytest_runtest_logstart(self, nodeid, location):
self.sendevent("logstart", nodeid=nodeid, location=location) self.sendevent("logstart", nodeid=nodeid, location=location)
# the pytest_runtest_logfinish hook was introduced in pytest 3.4 def pytest_runtest_logfinish(self, nodeid, location):
if hasattr(_pytest.hookspec, "pytest_runtest_logfinish"): self.sendevent("logfinish", nodeid=nodeid, location=location)
def pytest_runtest_logfinish(self, nodeid, location):
self.sendevent("logfinish", nodeid=nodeid, location=location)
def pytest_runtest_logreport(self, report): def pytest_runtest_logreport(self, report):
data = self.config.hook.pytest_report_to_serializable( data = self.config.hook.pytest_report_to_serializable(
@@ -125,29 +121,14 @@ class WorkerInteractor:
) )
self.sendevent("collectreport", data=data) self.sendevent("collectreport", data=data)
# the pytest_warning_recorded hook was introduced in pytest 6.0 def pytest_warning_recorded(self, warning_message, when, nodeid, location):
if hasattr(_pytest.hookspec, "pytest_warning_recorded"): self.sendevent(
"warning_recorded",
def pytest_warning_recorded(self, warning_message, when, nodeid, location): warning_message_data=serialize_warning_message(warning_message),
self.sendevent( when=when,
"warning_recorded", nodeid=nodeid,
warning_message_data=serialize_warning_message(warning_message), location=location,
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): def serialize_warning_message(warning_message):

View File

@@ -379,11 +379,7 @@ class WorkerController:
except: # noqa except: # noqa
from _pytest._code import ExceptionInfo from _pytest._code import ExceptionInfo
# ExceptionInfo API changed in pytest 4.1 excinfo = ExceptionInfo.from_current()
if hasattr(ExceptionInfo, "from_current"):
excinfo = ExceptionInfo.from_current()
else:
excinfo = ExceptionInfo()
print("!" * 20, excinfo) print("!" * 20, excinfo)
self.config.notify_exception(excinfo) self.config.notify_exception(excinfo)
self.shutdown() self.shutdown()

View File

@@ -1348,7 +1348,7 @@ def parse_tests_and_workers_from_output(lines):
r""" r"""
\[(gw\d)\] # worker \[(gw\d)\] # worker
\s* \s*
(?:\[\s*\d+%\])? # progress indicator (pytest >=3.3) (?:\[\s*\d+%\])? # progress indicator
\s(.*?) # status string ("PASSED") \s(.*?) # status string ("PASSED")
\s(.*::.*) # nodeid \s(.*::.*) # nodeid
""", """,