{"id":24564,"library":"scripttest","title":"scripttest","description":"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.","status":"maintenance","version":"2.0.post1","language":"python","source_language":"en","source_url":"https://github.com/pypa/scripttest","tags":["testing","cli","command-line","test"],"install":[{"cmd":"pip install scripttest","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"In version 1.x TestEnvironment was in scripttest.testing; in 2.x it's imported directly from scripttest.","wrong":"from scripttest.testing import TestEnvironment","symbol":"TestEnvironment","correct":"from scripttest import TestEnvironment"}],"quickstart":{"code":"import os\nimport sys\nfrom scripttest import TestEnvironment\n\ndef test_hello_world():\n    env = TestEnvironment()\n    # Run a simple echo command\n    result = env.run('echo', 'Hello World')\n    assert result.stdout == 'Hello World\\n'\n    assert result.returncode == 0\n    print(\"Test passed!\")\n\nif __name__ == '__main__':\n    test_hello_world()","lang":"python","description":"Basic usage: create a TestEnvironment, then run a command using env.run(). Check stdout, stderr, and returncode."},"warnings":[{"fix":"Access attributes: result.stdout, result.stderr, result.returncode instead of unpacking.","message":"TestEnvironment.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.","severity":"breaking","affected_versions":"<2.0"},{"fix":"Use 'from scripttest import TestEnvironment'.","message":"scripttest.testing module is deprecated; import TestEnvironment directly from scripttest.","severity":"deprecated","affected_versions":">=2.0"},{"fix":"Use env.set_cwd('/path') or pass cwd to run().","message":"By 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from scripttest import TestEnvironment'.","cause":"Importing from scripttest.testing in scripttest 2.x raises AttributeError because the submodule is removed.","error":"AttributeError: module 'scripttest' has no attribute 'testing'"},{"fix":"Access result.stdout, result.stderr, result.returncode instead of unpacking.","cause":"Unpacking the result of env.run() as a tuple is no longer supported in scripttest 2.x.","error":"TypeError: cannot unpack non-iterable Result object"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}