diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 93586d9..6515b82 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,9 @@ UNRELEASED * Drop support for EOL Python versions: 3.7, 3.8, 3.9. * Print proper child process exit status. * Removed dependency to `py `__. +* Fix tests marked with `@pytest.mark.forked` in pytest 7+. +* pytest >= 7 is now required. + v1.6.0 ====== diff --git a/setup.py b/setup.py index 108b4d8..a4263f4 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ ], }, zip_safe=False, - install_requires=["pytest>=3.10"], + install_requires=["pytest>=7"], setup_requires=["setuptools_scm"], python_requires=">=3.10", classifiers=[ diff --git a/src/pytest_forked/__init__.py b/src/pytest_forked/__init__.py index 6d678f2..6d135cb 100644 --- a/src/pytest_forked/__init__.py +++ b/src/pytest_forked/__init__.py @@ -44,13 +44,14 @@ def pytest_load_initial_conftests(early_config, parser, args): @pytest.hookimpl(tryfirst=True) -def pytest_runtest_protocol(item): +def pytest_runtest_protocol(item, nextitem): 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: ihook.pytest_runtest_logreport(report=rep) + item.session._setupstate.teardown_exact(nextitem) ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location) return True diff --git a/testing/test_boxed.py b/testing/test_boxed.py index 63c0515..3d67a9c 100644 --- a/testing/test_boxed.py +++ b/testing/test_boxed.py @@ -93,6 +93,29 @@ def test_function(): result.stdout.fnmatch_lines(["*EXITED with status 42*", "*1 failed*"]) +@needsfork +def test_forked_followed_by_other_test_tears_down(testdir): + testdir.makepyfile( + test_a=""" + import pytest + + def test_unforked(): + assert True + + @pytest.mark.forked + def test_forked(): + assert True + """, + test_b=""" + def test_other_module(): + assert True + """, + ) + result = testdir.runpytest() + result.stdout.fnmatch_lines(["*3 passed*"]) + assert result.ret == 0 + + def test_is_not_boxed_by_default(testdir): config = testdir.parseconfig(testdir.tmpdir) assert not config.option.forked