os-testr
os-testr is a Python library that acts as a wrapper for the `testr` (now often `stestr`) test runner, specifically providing additional functionality and integrations tailored for OpenStack projects. It enables features like `subunit-trace` for output filtering, `subunit2html` for HTML test reports, and `generate-subunit` for single test streams. The current version is 3.0.0, and its major release cadence is infrequent, typically aligning with broader OpenStack development cycles.
Common errors
-
Could not find a version that satisfies the requirement os-testr===X.Y.Z
cause This error typically occurs when a specific version of `os-testr` (e.g., 2.0.0) is requested but is not available in the configured PyPI indexes, or your `pip` version is too old to handle certain dependency resolutions.fixEnsure your `pip` is up to date (`pip install --upgrade pip`). If installing for an OpenStack project, check its `requirements.txt` or `setup.cfg` for the exact `os-testr` version constraint and verify if that version is still available on PyPI. You might need to adjust the version constraint if it's too restrictive for available packages. -
AttributeError: 'module' object has no attribute 'TestCase'
cause While not directly an `os-testr` error, this is a common Python testing mistake that can manifest when `os-testr` tries to run tests. It typically means you've accidentally named a test file `test.py` or a test class `TestCase` in a way that shadows the built-in `unittest.TestCase` or `testtools.TestCase`, leading to incorrect imports within your tests.fixRename conflicting test files or classes. Ensure your test files and classes have unique, descriptive names that don't clash with standard library modules or common test runner components. For example, avoid naming a file `test.py` if it contains test cases.
Warnings
- gotcha When using `testr` (which `os-testr` wraps), encountering 'The test run didn't actually run any tests' often indicates an underlying import error or issue during the test listing phase. The wrapper itself isn't running tests, but listing them for the runner.
- gotcha Direct debugging with `pdb.set_trace()` within tests run by `ostestr` (or `testr`/`stestr`) may not work as expected due to how `testr` forks processes and captures output.
Install
-
pip install os-testr
Imports
- CLI tool 'ostestr'
os-testr is primarily used as a command-line tool via 'ostestr'. Direct Python imports for end-user functionality are uncommon, as it wraps the testr/stestr runner.
Quickstart
# To run all tests in an OpenStack project directory: ostestr # To run specific tests matching a regex pattern: ostestr --regex '(my_project.tests.unit.test_module.TestClass.test_method)' # To run tests in serial mode (default is parallel): ostestr --serial # To run tests with a specific number of parallel workers: ostestr --concurrency 4 # To skip tests listed in a blacklist file: ostestr -b /path/to/skip_tests.txt