Fork helper for pytest
Project description
pytest-forks
This is a simple helper for pytest to support tests that fork or that test code that forks.
What it does
forks
detects forked children (and grandchildren) that fail to exit cleanly with os._exit
and reports them. It waits for all children to exit to ensure the parent doesn't perform tear-downs while any children are still active. It also prevents pytest from generating duplicate reports if a child fails to exit cleanly.
with forks()
calls can be safely nested if required.
Limitations
forks
cannot detect calls to os._exit
in the parent process. This will result in pytest failing to generate a report.
forks
cannot detect missing calls to os.waitpid
. This will result in unreaped children until pytest itself closes. forks
will correctly detect when these unreaped children exit.
forks
will not wait for children created through the subprocess module or with os.exec.
How to use it
import os
from pytest_forks import forks
def test_forking_code():
with forks():
# call code that forks
def test_forking_test():
with forks():
pid = os.fork()
if pid == 0:
# do things in the forked child
os._exit(0)
# do things in the parent
os.waitpid(pid, 0)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file pytest_forks-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pytest_forks-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95b59726d95dd8df6d7581ee917b845d0f606c61a2fb97da677c83466789f706 |
|
MD5 | b93724fe4ed9eef2f5af0ae9a6b225ba |
|
BLAKE2b-256 | 14b03d05b5c8df61e5f2414220237439cba8993d9e4dc06ea30f27034355e9f7 |