Skip to content

Commit 1477356

Browse files
webknjazThe-Compilerbluetech
committed
Merge PR #46
This change makes pytest-forked plugin pytest 6 ready. It replaces obsolete `tryfirst` mark, `pytest_runtest_logstart` and `pytest_runtest_logfinish` callbacks. The main fix is update of the `atexit` hack in our tests. Co-Authored-By: Florian Bruhin <me@the-compiler.org> Co-Authored-By: Ran Benita <ran@unusedvar.com>
2 parents b29c386 + 223bcf6 commit 1477356

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ env:
1212
- TOXENV=py-pytest310
1313
- TOXENV=py-pytest46
1414
- TOXENV=py-pytest54
15+
- TOXENV=py-pytest60
1516
- TOXENV=py-pytestlatest
17+
- TOXENV=py-pytestmaster
1618
matrix:
1719
exclude:
1820
- python: '2.7' # pytest 5+ does not support Python 2
1921
env: TOXENV=py-pytest54
22+
- python: '2.7' # pytest 5+ does not support Python 2
23+
env: TOXENV=py-pytest60
24+
- python: '2.7' # pytest 5+ does not support Python 2
25+
env: TOXENV=py-pytestmaster
26+
- python: '2.7' # Same as pytest54 for Python 2
27+
env: TOXENV=py-pytestlatest
2028
include:
2129
- python: '3.8'
2230
env: TOXENV=flakes

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v1.3.0
2+
======
3+
4+
* Add support for pytest 6 (issue #45 / PR #46)
5+
* Replace `@pytest.mark.tryfirst` with newer `@pytest.hookimpl` (PR #46)
6+
* Invoke `pytest_runtest_logstart` and `pytest_runtest_logfinish` hooks in `runtest_protocol` (issue #31 / PR #46)
7+
18
v1.2.0
29
======
310

src/pytest_forked/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ def pytest_load_initial_conftests(early_config, parser, args):
3838
)
3939

4040

41-
@pytest.mark.tryfirst
41+
@pytest.hookimpl(tryfirst=True)
4242
def pytest_runtest_protocol(item):
4343
if item.config.getvalue("forked") or item.get_closest_marker("forked"):
44+
ihook = item.ihook
45+
ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
4446
reports = forked_run_report(item)
4547
for rep in reports:
46-
item.ihook.pytest_runtest_logreport(report=rep)
48+
ihook.pytest_runtest_logreport(report=rep)
49+
ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
4750
return True
4851

4952

@@ -73,7 +76,7 @@ def runforked():
7376

7477

7578
def report_process_crash(item, result):
76-
from _pytest._code.source import getfslineno
79+
from _pytest._code import getfslineno
7780
path, lineno = getfslineno(item)
7881
info = ("%s:%s: running the test CRASHED with signal %d" %
7982
(path, lineno, result.signal))

testing/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ def _divert_atexit(request, monkeypatch):
99
import atexit
1010
atexit_fns = []
1111

12+
def atexit_register(func, *args, **kwargs):
13+
atexit_fns.append(lambda: func(*args, **kwargs))
14+
1215
def finish():
1316
while atexit_fns:
1417
atexit_fns.pop()()
1518

16-
monkeypatch.setattr(atexit, "register", atexit_fns.append)
19+
monkeypatch.setattr(atexit, "register", atexit_register)
1720
request.addfinalizer(finish)

testing/test_xfail_behavior.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_xfail(is_crashing, is_strict, testdir):
5353
session_start_title = '*==== test session starts ====*'
5454
loaded_pytest_plugins = 'plugins: forked*'
5555
collected_tests_num = 'collected 1 item'
56-
expected_progress = 'test_xfail.py {expected_letter!s}'.format(**locals())
56+
expected_progress = 'test_xfail.py {expected_letter!s}*'.format(**locals())
5757
failures_title = '*==== FAILURES ====*'
5858
failures_test_name = '*____ test_function ____*'
5959
failures_test_reason = '[XPASS(strict)] The process gets terminated'
@@ -112,6 +112,9 @@ def test_xfail(is_crashing, is_strict, testdir):
112112
113113
import pytest
114114
115+
# The current implementation emits RuntimeWarning.
116+
pytestmark = pytest.mark.filterwarnings('ignore:pytest-forked xfail')
117+
115118
@pytest.mark.xfail(
116119
reason='The process gets terminated',
117120
strict={is_strict!s},
@@ -123,9 +126,5 @@ def test_function():
123126
format(**locals())
124127
)
125128

126-
pytest_run_result = testdir.runpytest(
127-
test_module,
128-
'-ra',
129-
'-p', 'no:warnings', # the current implementation emits RuntimeWarning
130-
)
129+
pytest_run_result = testdir.runpytest(test_module, '-ra')
131130
pytest_run_result.stdout.fnmatch_lines(expected_lines)

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ deps =
1616
pytest310: pytest~=3.10
1717
pytest46: pytest~=4.6
1818
pytest54: pytest~=5.4
19+
pytest60: pytest~=6.0rc1
1920
pytestlatest: pytest
21+
pytestmaster: git+https://github.com/pytest-dev/pytest.git@master
2022
platform=linux|darwin
2123
commands=
2224
pytest {posargs}

0 commit comments

Comments
 (0)