pytest-regex is a pytest plugin that allows users to select tests for execution using regular expressions against the full test node ID. It extends pytest's test selection capabilities beyond keyword (`-k`) and marker (`-m`) expressions. The current version is 0.2.0, and it maintains an infrequent release cadence.
pip install pytest-regexVerified import paths — ran on the pinned version, not inferred.
Create a `test_example.py` file with some tests. Then, install `pytest` and `pytest-regex`. Run pytest from the command line using the `--regex` flag to filter tests based on a regular expression matching the full test node ID (e.g., `test_example.py::test_add`).
Ensure your regex pattern accounts for the full test node ID. Use `pytest --collect-only` to see the full node IDs before constructing complex patterns.
Use `subprocess` to call `pytest` with the desired command-line arguments if programmatic execution with regex filtering is required.
Start with only the `--regex` filter to confirm your pattern works, then gradually add other filters. If no tests are collected, try removing filters one by one to isolate the issue.