skillfed

pytest-console-scripts

Pytest plugin for testing console scripts

pytest-console-scripts v1.4.1 241.5K downloads/30d#8,876 on PyPI87
Permissive license MIT AGING released

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-scripts

uv

uv add pytest-console-scripts

poetry

poetry add pytest-console-scripts

Installing 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

Development Status :: 4 - BetaFramework :: 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.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing

Tags

pytest plugin run console scriptstest python scripts subprocesspytest script runner fixturein-process script execution testingconsole entry point testing
cli-testingscript-runnerpytest-plugin

More Testing packages