Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pytest_forks-1.0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_forks-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_forks-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95b59726d95dd8df6d7581ee917b845d0f606c61a2fb97da677c83466789f706
MD5 b93724fe4ed9eef2f5af0ae9a6b225ba
BLAKE2b-256 14b03d05b5c8df61e5f2414220237439cba8993d9e4dc06ea30f27034355e9f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page