fix testcase fail with Pytest6 and Pytest5
This commit is contained in:
parent
01f0e7f734
commit
b108a9adb9
63
0001-fix-testcase-fail-with-Pytest6-and-Pytest5.patch
Normal file
63
0001-fix-testcase-fail-with-Pytest6-and-Pytest5.patch
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
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
|
||||||
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
From 1eb5791e005c0d17622c53d5c3158b5b899e147e Mon Sep 17 00:00:00 2001
|
|
||||||
From: Stanislav Levin <slev@altlinux.org>
|
|
||||||
Date: Thu, 7 May 2020 14:40:19 +0300
|
|
||||||
Subject: [PATCH] Add compatibility with Pytest 5.4.0+
|
|
||||||
|
|
||||||
'getfslineno' has been removed from 'compat' in Pytest [0].
|
|
||||||
However, that function was just the wrapper of
|
|
||||||
'_pytest._code.source.getfslineno'. The latter exists in Pytest
|
|
||||||
since, at least, 3.0.0.
|
|
||||||
|
|
||||||
[0]: https://github.com/pytest-dev/pytest/commit/9c7f1d9b3.
|
|
||||||
|
|
||||||
Fixes: https://github.com/pytest-dev/pytest-forked/issues/30
|
|
||||||
Signed-off-by: Stanislav Levin <slev@altlinux.org>
|
|
||||||
---
|
|
||||||
src/pytest_forked/__init__.py | 9 ++-------
|
|
||||||
1 file changed, 2 insertions(+), 7 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/src/pytest_forked/__init__.py b/src/pytest_forked/__init__.py
|
|
||||||
index fa0600d..886c4c8 100644
|
|
||||||
--- a/src/pytest_forked/__init__.py
|
|
||||||
+++ b/src/pytest_forked/__init__.py
|
|
||||||
@@ -71,13 +71,8 @@ def runforked():
|
|
||||||
|
|
||||||
|
|
||||||
def report_process_crash(item, result):
|
|
||||||
- try:
|
|
||||||
- from _pytest.compat import getfslineno
|
|
||||||
- except ImportError:
|
|
||||||
- # pytest<4.2
|
|
||||||
- path, lineno = item._getfslineno()
|
|
||||||
- else:
|
|
||||||
- path, lineno = getfslineno(item)
|
|
||||||
+ from _pytest._code.source import getfslineno
|
|
||||||
+ path, lineno = getfslineno(item)
|
|
||||||
info = ("%s:%s: running the test CRASHED with signal %d" %
|
|
||||||
(path, lineno, result.signal))
|
|
||||||
from _pytest import runner
|
|
||||||
@ -6,14 +6,14 @@ C++ libraries that might crash the process. To use the plugin, simply use the\
|
|||||||
|
|
||||||
Name: python-%{pypi_name}
|
Name: python-%{pypi_name}
|
||||||
Version: 1.0.2
|
Version: 1.0.2
|
||||||
Release: 1
|
Release: 2
|
||||||
Summary: py.test plugin for running tests in isolated forked subprocesses
|
Summary: py.test plugin for running tests in isolated forked subprocesses
|
||||||
|
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: https://github.com/pytest-dev/pytest-forked
|
URL: https://github.com/pytest-dev/pytest-forked
|
||||||
Source0: https://files.pythonhosted.org/packages/source/p/%{pypi_name}/%{pypi_name}-%{version}.tar.gz
|
Source0: https://files.pythonhosted.org/packages/source/p/%{pypi_name}/%{pypi_name}-%{version}.tar.gz
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
Patch1: add-compatibility-with-Pytest-5.4.0.patch
|
Patch1: 0001-fix-testcase-fail-with-Pytest6-and-Pytest5.patch
|
||||||
|
|
||||||
BuildRequires: python3-devel
|
BuildRequires: python3-devel
|
||||||
BuildRequires: python3-py python3-pytest python3-setuptools_scm
|
BuildRequires: python3-py python3-pytest python3-setuptools_scm
|
||||||
@ -49,6 +49,9 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} py.test-%{python3_version} testing
|
|||||||
%{python3_sitelib}/pytest_forked*
|
%{python3_sitelib}/pytest_forked*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Aug 25 2021 liyanan <liyanan32@huawei.com> - 1.0.2-2
|
||||||
|
- fix test case fail with Pytest6 and Pytest5
|
||||||
|
|
||||||
* Tue Jul 06 2021 wangdi <wangdi@kylinos.cn> - 1.0.2-1
|
* Tue Jul 06 2021 wangdi <wangdi@kylinos.cn> - 1.0.2-1
|
||||||
- Init package for version 1.0.2
|
- Init package for version 1.0.2
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user