pytest-subprocess
A plugin to fake subprocess for pytest
Decision gist · record as of 2026-08-14
Yes. This is a mature, actively maintained plugin with no security issues, low install friction, and a permissive license. It directly solves the common testing problem of isolating code that calls external processes. Install it if your test suite includes code that uses subprocess.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction install with a single runtime dependency (pytest).
- The package is actively maintained with a recent release and no known vulnerabilities, making it straightforward to add to test suites.
License · maintenance · safety
MIT (permissive) — MIT license is permissive, allowing use in commercial and open-source projects with minimal restrictions—just include the license text.
last release 2026-05-10 (96 days) · last repo commit 2026-05-26 · 117 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 514,874 downloads/mo, #6,237 on PyPI
Alternatives
Verify before relying
pip install pytest-subprocess
import subprocess
def test_example(fp):
fp.register(["echo", "hello"], stdout="hello")
result = subprocess.run(["echo", "hello"], capture_output=True, text=True)
assert result.stdout == "hello"- Whether the plugin works with subprocess.Popen subclasses or only the standard library implementation
- Performance overhead when registering many subprocess calls in a single test suite
What it is and what it does
pytest-subprocess is a pytest plugin that intercepts calls to subprocess.Popen and its higher-level wrappers (subprocess.run, subprocess.call, subprocess.check_call, subprocess.check_output) to replace them with fake implementations. Instead of executing real system commands during tests, you register expected commands and their outputs using the fp fixture, which then returns those outputs when your code calls subprocess. This eliminates test dependencies on external tools, makes tests faster and more reliable, and lets you simulate error conditions and edge cases that would be hard to trigger with real processes.
The plugin supports registering different outputs for repeated calls to the same command, passing input to stdin with custom handling logic, allowing unregistered commands to fall through to real subprocess execution, and using callbacks to inject custom behavior. It works across all subprocess functions because they all ultimately call Popen internally. The fixture is available both as fp and the longer form fake_process.
Use it for
- Test code that shells out to git, docker, or other CLI tools without requiring those tools to be installed or available in CI
- Simulate subprocess failures and non-zero exit codes to verify error handling paths in your application
- Mock multi-step command sequences where each call returns different output, testing state-dependent subprocess behavior
- Verify that your code passes the correct arguments and environment to subprocess without actually executing them
- Test subprocess input/output handling by registering stdin callbacks that transform input into output
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
This is a mature, actively maintained plugin with no security issues, low install friction, and a permissive license. It directly solves the common testing problem of isolating code that calls external processes. Install it if your test suite includes code that uses subprocess.
Install
pytest-subprocess on PyPI
Before you install
Low friction install with a single runtime dependency (pytest). The package is actively maintained with a recent release and no known vulnerabilities, making it straightforward to add to test suites.
License in practice
MIT license is permissive, allowing use in commercial and open-source projects with minimal restrictions—just include the license text.
Quickstart
pip install pytest-subprocess
import subprocess
def test_example(fp):
fp.register(["echo", "hello"], stdout="hello")
result = subprocess.run(["echo", "hello"], capture_output=True, text=True)
assert result.stdout == "hello"
Verify before relying
- Whether the plugin works with subprocess.Popen subclasses or only the standard library implementation
- Performance overhead when registering many subprocess calls in a single test suite
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.6 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagepytest |
| Maintenance | Actively maintained 96 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 514,874 / month, #6,237 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing |
Evidence: pytest_subprocess-1.6.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mock subprocess calls in tests”
- pytest-subprocessPytest plugin that intercepts and fakes subprocess calls, allowing…
- testfixturesTestfixtures provides helpers and mock objects for writing unit and…
- requests-mockIntercepts and mocks HTTP requests made through the requests library,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also pytest-console-scripts · pytest-forked · pytest-responses · EasyProcess · scripttest · pytest-mock · pytest-depends · pytest_httpserver · pytest-httpx2 · pytest-reportportal