Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# 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

- Usage
  - Installation
  - Basic usage
  - Passing input
  - Unregistered commands
  - Differing results
  - Using callbacks
  - As a context manager
  - Non-exact command matching
  - Check if process was called
  - Check Popen arguments
  - Handling signals
  - Asyncio support
- API Reference
  - fake_subprocess
  - any()
- History
  - 1.5.3 (2025-01-04)
  - 1.5.2 (2024-07-24)
  - 1.5.1 (2024-07-23)
  - 1.5.0 (2023-01-28)
  - 1.4.2 (2022-10-02)
  - 1.4.1 (2022-02-09)
  - 1.4.0 (2022-01-23)
  - 1.3.2 (2021-11-07)
  - 1.3.1 (2021-11-01)
  - 1.3.0 (2021-10-24)
  - 1.2.0 (2021-10-09)
  - 1.1.2 (2021-07-17)
  - 1.1.1 (2021-06-18)
  - 1.1.0 (2021-04-18)
  - 1.0.1 (2021-03-20)
  - 1.0.0 (2020-08-22)
  - 0.1.5 (2020-06-19)
  - 0.1.4 (2020-04-28)
  - 0.1.3 (2020-03-04)
  - 0.1.2 (2020-01-17)
  - 0.1.1 (2019-11-24)
  - 0.1.0 (2019-11-23)

# Indices and tables

- Index

- Module Index

- Search Page