Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pypi.org/project/py>`__.
* Fix tests marked with `@pytest.mark.forked` in pytest 7+.
* pytest >= 7 is now required.


v1.6.0
======
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
3 changes: 2 additions & 1 deletion src/pytest_forked/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
Dreamsorcerer marked this conversation as resolved.
return True

Expand Down
23 changes: 23 additions & 0 deletions testing/test_boxed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading