pytest-subprocess#

This is a pytest plugin to fake the real subprocess behavior to make your tests more independent.

Example#

You can use the provided fake_process (or fp for short) fixture to register commands and specify their behavior before they will be executed. This will prevent a real subprocess execution.

def test_process(fp):
    fp.register(["fake-command"])
    process = subprocess.run(["fake-command"])

    assert process.returncode == 0

Table of contents#

Indices and tables#