{"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":[{"wrong":"from scripttest import TestEnvironment","symbol":"TestFileEnvironment","correct":"from scripttest import TestFileEnvironment"}],"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,"search_vec":"'2.0':27 'applic':11 'cadenc':30 'captur':19 'cli':10,40 'command':7,42 'command-lin':6,41 'current':25 'librari':3 'line':8,43 'low':32 'new':34 'post1':28 'provid':15 'python':13 'releas':29,35 'script':9 'scripttest':1 'sever':37 'simul':23 'stderr':21 'stdin':24 'stdout':20 'test':5,39,44 'testenviron':17 'version':26 'year':38","created_at":"2026-05-01T08:13:44.849164+00:00","updated_at":"2026-05-01T08:13:44.849164+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.0.post1","cli_name":"","cli_version":null,"type":"library","homepage":"https://scripttest.readthedocs.io/en/stable/","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/scripttest/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}