Registry / testing / pytest-regex

pytest-regex

JSON →
library0.2.0pypypiunverified

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-regex
INSTALL
IMPORT
SIG · PYTEST-REGEX
P
pytest-regex
testingpythonv0.2.0
Install
—
Import
—
Disk
—
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
timeout
glibc
py 3.10–3.920 runs
timeout
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest-regex
✓ This library is a pytest plugin; its functionality is accessed via the `pytest` command-line interface, not through direct Python imports.
Users do not import symbols from `pytest_regex` directly. The plugin integrates with pytest's test collection and selection mechanisms.

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`).

import pytest # test_example.py def test_add(): assert 1 + 1 == 2 def test_subtract(): assert 2 - 1 == 1 class TestMathOperations: def test_multiply(self): assert 2 * 2 == 4 # To run: save the above as 'test_example.py' # Then run from your terminal: # pip install pytest pytest-regex # pytest --regex "test_add" # pytest --regex "TestMathOperations::test_multiply" # pytest --regex "^(test_add|test_subtract)$"
Debug
Known issues
gotchaThe `--regex` flag matches against the *full test node ID*, which includes the file path, module, class, and function name (e.g., `test_module.py::TestClass::test_method`). Simple patterns like `test_my_func` might not match if the full path isn't considered.
fix
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.
affects: All versions
gotchapytest-regex functionality is exclusively exposed via command-line arguments (`--regex` and `--regex-file`). There is no public Python API for direct programmatic interaction with the plugin's regex matching logic.
fix
Use `subprocess` to call `pytest` with the desired command-line arguments if programmatic execution with regex filtering is required.
affects: All versions
gotchaWhen combining `--regex` with other selection options like `-k` (keyword) or `-m` (marker), pytest typically applies all filters. An overly restrictive combination of filters can lead to 'No tests ran'.
fix
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.
affects: All versions
Upgrade
Version history
0.2.0latest on PyPI · released May 29, 2023
Audit
Dependencies
pytestrequiredThis is a pytest plugin and requires pytest to function.
Agent activity
9 hits · last 30 days
node
8
Resources
pytest-regex — pip install pytest-regex · libregistry