From b25d3c3b07068c7037a3ad138c368d9d658756da Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 24 Jul 2020 10:57:34 +0300 Subject: [PATCH 1/8] testing: make the atexit monkeypatch more robust, needed for pytest 6 --- testing/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/testing/conftest.py b/testing/conftest.py index 745c00f..6ac720b 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -9,9 +9,12 @@ 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) From 81b9e9e217afea022419eccdbf933d5025512c32 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 24 Jul 2020 11:03:08 +0300 Subject: [PATCH 2/8] Change import of getfslineno to be compatible with pytest 6 Really it is private and shouldn't be imported at all, but that's for another time... Debugged by Florian Bruhin. --- src/pytest_forked/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_forked/__init__.py b/src/pytest_forked/__init__.py index 763d7ab..d5fae71 100644 --- a/src/pytest_forked/__init__.py +++ b/src/pytest_forked/__init__.py @@ -73,7 +73,7 @@ def runforked(): def report_process_crash(item, result): - from _pytest._code.source import getfslineno + from _pytest._code import getfslineno path, lineno = getfslineno(item) info = ("%s:%s: running the test CRASHED with signal %d" % (path, lineno, result.signal)) From 6c5038356c711528598dc7eaa3e4dd86b9f7b241 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 24 Jul 2020 11:23:27 +0300 Subject: [PATCH 3/8] Use @pytest.hookimpl instead of soft-deprecated @pytest.mark.tryfirst --- src/pytest_forked/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_forked/__init__.py b/src/pytest_forked/__init__.py index d5fae71..1b491e9 100644 --- a/src/pytest_forked/__init__.py +++ b/src/pytest_forked/__init__.py @@ -38,7 +38,7 @@ def pytest_load_initial_conftests(early_config, parser, args): ) -@pytest.mark.tryfirst +@pytest.hookimpl(tryfirst=True) def pytest_runtest_protocol(item): if item.config.getvalue("forked") or item.get_closest_marker("forked"): reports = forked_run_report(item) From 6274c3ce71a9071960bd6615d1cd4d37d9c30adf Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 24 Jul 2020 12:29:11 +0300 Subject: [PATCH 4/8] Also call pytest_runtest_log{start,finish} hooks Otherwise some reporting is missing. In particular, pytest 6 moves some output to these hooks. --- src/pytest_forked/__init__.py | 5 ++++- testing/test_xfail_behavior.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pytest_forked/__init__.py b/src/pytest_forked/__init__.py index 1b491e9..dd15961 100644 --- a/src/pytest_forked/__init__.py +++ b/src/pytest_forked/__init__.py @@ -41,9 +41,12 @@ def pytest_load_initial_conftests(early_config, parser, args): @pytest.hookimpl(tryfirst=True) def pytest_runtest_protocol(item): if item.config.getvalue("forked") or item.get_closest_marker("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 diff --git a/testing/test_xfail_behavior.py b/testing/test_xfail_behavior.py index 3ec1096..f1bf1cf 100644 --- a/testing/test_xfail_behavior.py +++ b/testing/test_xfail_behavior.py @@ -53,7 +53,7 @@ def test_xfail(is_crashing, is_strict, testdir): session_start_title = '*==== test session starts ====*' loaded_pytest_plugins = 'plugins: forked*' collected_tests_num = 'collected 1 item' - expected_progress = 'test_xfail.py {expected_letter!s}'.format(**locals()) + expected_progress = 'test_xfail.py {expected_letter!s}*'.format(**locals()) failures_title = '*==== FAILURES ====*' failures_test_name = '*____ test_function ____*' failures_test_reason = '[XPASS(strict)] The process gets terminated' From a7462c6d167fadcb940350e8469838f76e37a53d Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 24 Jul 2020 13:02:19 +0300 Subject: [PATCH 5/8] testing: ignore warning entirely otherwise it interferes with the fnmatching --- testing/test_xfail_behavior.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/testing/test_xfail_behavior.py b/testing/test_xfail_behavior.py index f1bf1cf..f40258b 100644 --- a/testing/test_xfail_behavior.py +++ b/testing/test_xfail_behavior.py @@ -112,6 +112,9 @@ def test_xfail(is_crashing, is_strict, testdir): import pytest + # The current implementation emits RuntimeWarning. + pytestmark = pytest.mark.filterwarnings('ignore:pytest-forked xfail') + @pytest.mark.xfail( reason='The process gets terminated', strict={is_strict!s}, @@ -123,9 +126,5 @@ def test_function(): format(**locals()) ) - pytest_run_result = testdir.runpytest( - test_module, - '-ra', - '-p', 'no:warnings', # the current implementation emits RuntimeWarning - ) + pytest_run_result = testdir.runpytest(test_module, '-ra') pytest_run_result.stdout.fnmatch_lines(expected_lines) From 6672e4d12c2fad3e1a9782b827ccfb29c81a4551 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 24 Jul 2020 12:30:45 +0300 Subject: [PATCH 6/8] tox: add pytestmaster and pytest60 environments --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 6643bd2..72f530b 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,9 @@ deps = pytest310: pytest~=3.10 pytest46: pytest~=4.6 pytest54: pytest~=5.4 + pytest60: pytest~=6.0rc1 pytestlatest: pytest + pytestmaster: git+https://github.com/pytest-dev/pytest.git@master platform=linux|darwin commands= pytest {posargs} From 3bc1376eff73670a0866264404637e3e8118ecf8 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 27 Jul 2020 15:36:00 +0300 Subject: [PATCH 7/8] ci: add pytestmaster and pytest60 to test matrix --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index e5314d2..c2a044a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,19 @@ env: - TOXENV=py-pytest310 - TOXENV=py-pytest46 - TOXENV=py-pytest54 + - TOXENV=py-pytest60 - TOXENV=py-pytestlatest + - TOXENV=py-pytestmaster matrix: exclude: - python: '2.7' # pytest 5+ does not support Python 2 env: TOXENV=py-pytest54 + - python: '2.7' # pytest 5+ does not support Python 2 + env: TOXENV=py-pytest60 + - python: '2.7' # pytest 5+ does not support Python 2 + env: TOXENV=py-pytestmaster + - python: '2.7' # Same as pytest54 for Python 2 + env: TOXENV=py-pytestlatest include: - python: '3.8' env: TOXENV=flakes From 223bcf68516724a718b3b86f24be7ea53a3bf3e1 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 27 Jul 2020 21:18:49 +0200 Subject: [PATCH 8/8] Add change notes for v1.3.0 --- CHANGELOG | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 9f4ccf6..7117c95 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +v1.3.0 +====== + +* Add support for pytest 6 (issue #45 / PR #46) +* Replace `@pytest.mark.tryfirst` with newer `@pytest.hookimpl` (PR #46) +* Invoke `pytest_runtest_logstart` and `pytest_runtest_logfinish` hooks in `runtest_protocol` (issue #31 / PR #46) + v1.2.0 ======