{"library":"pytest-subprocess","title":"pytest-subprocess","description":"pytest-subprocess is a pytest plugin that allows faking the behavior of `subprocess` calls within tests, eliminating the need to rely on actual external processes. It hooks into `subprocess.Popen()` and consequently handles `subprocess.run()`, `subprocess.call()`, `subprocess.check_call()`, and `subprocess.check_output()` methods. The library is actively maintained with regular releases, ensuring compatibility and new features.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install pytest-subprocess"],"cli":null},"imports":["def test_something(fake_process):\n    # use fake_process here"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import subprocess\nimport pytest\n\ndef test_process_command(fp):\n    # Register a fake command and its expected output\n    fp.register(['fake-command'], stdout='Hello from fake-command')\n\n    # Run the command using subprocess (it will be faked by pytest-subprocess)\n    process = subprocess.run(['fake-command'], capture_output=True, text=True)\n\n    # Assert on the faked process's behavior\n    assert process.returncode == 0\n    assert process.stdout.strip() == 'Hello from fake-command'\n\ndef test_command_with_args(fp):\n    fp.register(['greet', 'world'], stdout='Greeting world!')\n    process = subprocess.run(['greet', 'world'], capture_output=True, text=True)\n    assert process.returncode == 0\n    assert process.stdout.strip() == 'Greeting world!'","lang":"python","description":"This example demonstrates how to use the `fp` (alias for `fake_process`) fixture to register a command and define its `stdout`. When `subprocess.run()` is called with the registered command, `pytest-subprocess` intercepts it and provides the faked output and return code.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"1.6.0","pypi_latest":"1.6.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.7,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"30.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.7,"import_time_s":null,"mem_mb":null,"disk_size":"31M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"33.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.6,"import_time_s":null,"mem_mb":null,"disk_size":"34M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"25.4M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.4,"import_time_s":null,"mem_mb":null,"disk_size":"26M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"25.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":2.5,"import_time_s":null,"mem_mb":null,"disk_size":"26M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"30.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pytest-subprocess","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.1,"import_time_s":null,"mem_mb":null,"disk_size":"31M"}]}}