64 lines
2.1 KiB
Diff
64 lines
2.1 KiB
Diff
From 41931fe962963874fc0128a4ef6ff6cf229b0c08 Mon Sep 17 00:00:00 2001
|
|
From: lyn1001 <thistleslyn@163.com>
|
|
Date: Wed, 25 Aug 2021 14:23:06 +0800
|
|
Subject: [PATCH] fix testcase fail with Pytest6 and Pytest5
|
|
|
|
---
|
|
a/src/pytest_forked/__init__.py | 9 ++++++---
|
|
a/testing/conftest.py | 5 ++++-
|
|
2 files changed, 10 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/pytest_forked/__init__.py b/src/pytest_forked/__init__.py
|
|
index 33b09d2..84fb768 100644
|
|
--- a/src/pytest_forked/__init__.py
|
|
+++ b/src/pytest_forked/__init__.py
|
|
@@ -29,12 +29,15 @@ def pytest_addoption(parser):
|
|
help="box each test run in a separate process (unix)")
|
|
|
|
|
|
-@pytest.mark.tryfirst
|
|
+@pytest.hookimpl(tryfirst=True)
|
|
def pytest_runtest_protocol(item):
|
|
if item.config.getvalue("forked"):
|
|
+ ihook = item.ihook
|
|
+ ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
|
|
reports = forked_run_report(item)
|
|
for rep in reports:
|
|
- item.ihook.pytest_runtest_logreport(report=rep)
|
|
+ ihook.pytest_runtest_logreport(report=rep)
|
|
+ ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
|
|
return True
|
|
|
|
|
|
@@ -65,7 +68,7 @@ def forked_run_report(item):
|
|
|
|
def report_process_crash(item, result):
|
|
try:
|
|
- from _pytest.compat import getfslineno
|
|
+ from _pytest._code import getfslineno
|
|
except ImportError:
|
|
# pytest<4.2
|
|
path, lineno = item._getfslineno()
|
|
diff --git a/testing/conftest.py b/testing/conftest.py
|
|
index 745c00f..c01f73e 100644
|
|
--- a/testing/conftest.py
|
|
+++ b/testing/conftest.py
|
|
@@ -8,10 +8,13 @@ pytest_plugins = "pytester"
|
|
def _divert_atexit(request, monkeypatch):
|
|
import atexit
|
|
atexit_fns = []
|
|
+
|
|
+ def atexit_register(func, *args, **kwargs):
|
|
+ atexit_fns.append(lambda: func(*args, **kwargs))
|
|
|
|
def finish():
|
|
while atexit_fns:
|
|
atexit_fns.pop()()
|
|
|
|
- monkeypatch.setattr(atexit, "register", atexit_fns.append)
|
|
+ monkeypatch.setattr(atexit, "register", atexit_register)
|
|
request.addfinalizer(finish)
|
|
--
|
|
2.23.0
|
|
|