Registry / testing / scripttest

scripttest

JSON →
library2.0.post1pypypi✓ verified 79d ago

A library for testing command-line scripts (CLI applications) in Python. It provides a TestEnvironment that captures stdout, stderr, and simulates stdin. Current version 2.0.post1. Release cadence is low; no new releases for several years.

pip install scripttest
INSTALL
IMPORT
SIG · SCRIPTTEST
S
scripttest
testingpythonv2.0.post1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.post1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TestFileEnvironment
from scripttest import TestFileEnvironment
from scripttest import TestEnvironment

Basic usage: create a TestEnvironment, then run a command using env.run(). Check stdout, stderr, and returncode.

import os import sys from scripttest import TestEnvironment def test_hello_world(): env = TestEnvironment() # Run a simple echo command result = env.run('echo', 'Hello World') assert result.stdout == 'Hello World\n' assert result.returncode == 0 print("Test passed!") if __name__ == '__main__': test_hello_world()
Debug
Known issues
breakingTestEnvironment.run() no longer returns a tuple; it returns a Result object with .stdout, .stderr, .returncode attributes. Code using tuple unpacking (stdout, stderr, returncode) in scripttest 1.x will break.
fix
Access attributes: result.stdout, result.stderr, result.returncode instead of unpacking.
affects: <2.0
deprecatedscripttest.testing module is deprecated; import TestEnvironment directly from scripttest.
fix
Use 'from scripttest import TestEnvironment'.
affects: >=2.0
gotchaBy default, TestEnvironment runs commands in a temporary directory. Access to the current working directory or files outside the temp dir may require explicit path setup.
fix
Use env.set_cwd('/path') or pass cwd to run().
affects: all
Upgrade
Version history
2.0.post1latest on PyPI · released Apr 9, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
14
Resources
scripttest — pip install scripttest · libregistry