{"library":"stestr","title":"stestr: Parallel Python Test Runner","type":"library","description":"stestr is a parallel Python test runner built around the `subunit` stream protocol. It provides a robust command-line interface for discovering, running, and managing tests, designed to efficiently handle large test suites and integrate well into continuous integration pipelines. The current version is 4.2.1, with minor and patch releases occurring every few months to enhance compatibility and add features.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install stestr"],"cli":{"name":"stestr","version":"stestr 4.2.1"}},"imports":[],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://stestr.readthedocs.io/en/stable/","github":"https://github.com/mtreinish/stestr","docs":"https://stestr.readthedocs.io","changelog":null,"pypi":"https://pypi.org/project/stestr/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import os\nimport subprocess\nimport shutil\nimport tempfile\n\n# Create a temporary directory for demonstration\ntemp_dir = tempfile.mkdtemp()\ncurrent_dir = os.getcwd()\nos.chdir(temp_dir)\n\ntry:\n    # 1. Create a 'tests' directory\n    os.makedirs(\"tests\")\n\n    # 2. Create a simple unittest file\n    test_code = \"\"\"\nimport unittest\n\nclass ExampleTests(unittest.TestCase):\n    def test_success(self):\n        self.assertTrue(True)\n\n    def test_failure(self):\n        self.assertFalse(False, \"This test is designed to fail.\")\n\n    def test_another_success(self):\n        self.assertEqual(2 + 2, 4)\n\"\"\"\n    with open(\"tests/test_my_app.py\", \"w\") as f:\n        f.write(test_code)\n\n    # 3. Create a stestr configuration file (e.g., setup.cfg or .stestr.conf)\n    # Using setup.cfg for modern compatibility\n    config_code = \"\"\"\n[stestr]\ntest_path = tests\ntest_file_prefix = test_\n\"\"\"\n    with open(\"setup.cfg\", \"w\") as f:\n        f.write(config_code)\n\n    print(f\"Working directory: {os.getcwd()}\")\n    print(\"\\n--- Initializing stestr repository ---\")\n    subprocess.run([\"stestr\", \"init\"], check=True)\n    print(\"\\n--- Running tests with stestr ---\")\n    result = subprocess.run([\"stestr\", \"run\"], capture_output=True, text=True)\n    print(result.stdout)\n    if result.stderr:\n        print(\"STDERR:\")\n        print(result.stderr)\n\n    if result.returncode != 0:\n        print(\"\\nNote: stestr run reported failures (expected for demonstration).\")\n    else:\n        print(\"\\nstestr run completed successfully.\")\n\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error: stestr command failed. Command: {' '.join(e.cmd)}\")\n    print(f\"Stdout: {e.stdout}\")\n    print(f\"Stderr: {e.stderr}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\nfinally:\n    os.chdir(current_dir)\n    shutil.rmtree(temp_dir)\n    print(f\"\\nCleaned up temporary directory: {temp_dir}\")\n","lang":"python","description":"This quickstart creates a temporary directory, sets up a basic `unittest` test suite and a `setup.cfg` for stestr configuration, then runs `stestr init` to initialize the test repository and `stestr run` to execute the tests. It demonstrates the typical command-line workflow for stestr.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}