pytest-console-scripts
Pytest plugin for testing console scripts
What it is and what it does
pytest-console-scripts is a pytest plugin that lets you test Python console scripts as if they were being run from the command line. It provides a `script_runner` fixture that captures output and return codes, and offers two execution modes: in-process (where the script runs in the same Python interpreter as pytest, speeding up test suites) and subprocess (where the script runs in a fresh interpreter, simulating real-world invocation more closely).
You can run scripts installed via console_scripts entry points, standalone Python files, or executables on the PATH. The plugin supports configuring execution mode globally via pytest config, per-test via command-line flags, or per-test via pytest markers. In-process mode enables mocking of script internals, while subprocess mode validates that scripts work correctly when invoked independently.
Use it for:
- Test CLI tools and console scripts installed via setup.py entry_points during development.
- Validate that scripts behave identically when run in-process (fast) and subprocess (realistic) modes.
- Capture and assert on stdout, stderr, and return codes from Python scripts in test suites.
- Mock functions inside console scripts during in-process test runs to isolate behavior.
- Speed up test iteration by running scripts in-process, then verify with subprocess mode in CI.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that runs Python console scripts within tests, supporting both in-process execution (fast iteration) and subprocess mode (realistic testing).
Yes, if you maintain Python CLI tools or console scripts and want to test them within pytest. The dual execution mode (in-process for speed, subprocess for realism) is a genuine advantage over subprocess.run() alone. However, note that the package is aging—last release was May 2023 with no recent commits—so verify compatibility with your pytest version before adopting. No known security vulnerabilities.
Install
pytest-console-scripts on PyPI
pip
pip install pytest-console-scriptsuv
uv add pytest-console-scriptspoetry
poetry add pytest-console-scriptsInstalling pytest-console-scripts
Before you install
Low friction install with only pytest and importlib-metadata as runtime dependencies. Maintenance status is aging—last release was 2023-05-31 and the repository shows no recent activity, though it remains unarchived.
License in practice
MIT license is permissive; you can use this package freely in commercial and open-source projects without restriction.
Quickstart
pip install pytest-console-scripts
from pytest_console_scripts import ScriptRunner
def test_script(script_runner: ScriptRunner):
result = script_runner.run(['my-script', '--version'])
assert result.returncode == 0
Requires Python 3.8+ and pytest 4.0 or newer. Console scripts must be installed (via entry_points or on PATH) before tests run.
Verify before relying
- Whether the aging maintenance status (last release May 2023) affects compatibility with recent pytest versions.
- Current test coverage and whether the package is actively maintained despite unarchived status.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pytest, importlib-metadata |
| Maintenance | aging — 1,171 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 241,463/month — #8,876 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_console_scripts-1.4.1-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-subprocessPytest plugin that intercepts and fakes…
permissive · top 15,000 on PyPI
pytest-loggingA pytest plugin that configures Python logging…
permissive · top 15,000 on PyPI
pytest-subtestsAdds subTest() support to pytest, allowing…
permissive · top 5,000 on PyPI
pytest-mockProvides a pytest fixture that wraps the mock…
permissive · top 1,000 on PyPI
pytest-httpx2A pytest plugin that mocks httpx2 HTTP requests…
permissive · top 15,000 on PyPI
pytest-grpcA pytest plugin that provides fixtures to write…
permissive · top 15,000 on PyPI
pytest-ansibleA pytest plugin that integrates Ansible into…
permissive · top 5,000 on PyPI
subprocess-teeA drop-in replacement for subprocess.run that…
permissive · top 5,000 on PyPI
pytest_httpserverA pytest fixture and standalone context manager…
unclear · top 5,000 on PyPI
pytest-freezegunpytest-freezegun provides a pytest plugin that…
permissive · top 5,000 on PyPI