pytest-regex
Use Python Standard Library Regular Expressions to Specify Tests to Run
After installing locally with i.e., python -m pip install . you can compare it with more conventional test selection techniques as follows.
Consider working with SciPy development. Let’s start off by selecting all tests with test_3d anywhere in their node id, using the conventional/ built-in -k flag:
python dev.py test – -v -k “test_3d”
This runs a bunch of tests with string matches as you might expect:
scipy/io/tests/test_idl.py::TestArrayDimensions::test_3d PASSED scipy/io/tests/test_idl.py::TestPointerArray::test_3d PASSED scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestBoxBoundariesIntersections::test_3d_box_constraints PASSED scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestBoxBoundariesIntersections::test_3d_box_constraints_entire_line PASSED scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestModifiedDogleg::test_3d_example PASSED scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array PASSED scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_type_tuple PASSED scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_0 PASSED scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_1 PASSED scipy/stats/tests/test_stats.py::TestGeometricStandardDeviation::test_3d_array_axis_2 PASSED scipy/stats/tests/test_stats.py::TestFOneWay::test_3d_inputs PASSED
What if you want to run only tests with an exact match to test_3d or test_3d_example?
- Try pytest-regex with:
python dev.py test – -v –regex “(.*test_3d$|.*test_3d_example$)”
scipy/io/tests/test_idl.py::TestArrayDimensions::test_3d PASSED scipy/io/tests/test_idl.py::TestPointerArray::test_3d PASSED scipy/optimize/_trustregion_constr/tests/test_qp_subproblem.py::TestModifiedDogleg::test_3d_example PASSED
This does what we want, and is probably more concise than the -k alternative. In fact, I’m not entirely sure how one would do this with -k in its current form.
How it Works
pytest-regex simply passes the Python regular expression through to the list of node ids, where a node id is structured as follows:
path/to/test_module.py::TestClass::test_name[parameter_value]
If the regex matches the node id, the test is retained and executed.
Metadata
Release files for pytest-regex 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-regex-0.2.0.tar.gz | 4.1 kB | Without provenance | Details for pytest-regex-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_regex-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_regex-0.2.0-py3-none-any.whl |
Total release size: 7.9 kB
Release files / pytest-regex-0.2.0.tar.gz
| Download URL | pytest-regex-0.2.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4076c49abece2503815c8b2e282a8fd22d330f06f9bf91d620b3ef02de7a353
|
|
BLAKE2b-256 checksum How to use checksums |
7367e3f3700e8f95fc9e80ab83d589346c117de4e6d01e6b922f7300282e7fc9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / pytest_regex-0.2.0-py3-none-any.whl
| Download URL | pytest_regex-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c97e9c49e8c7e7482bd1fa701e3a5cccd18eb78d263752e32dba4937d8cee6d9
|
|
BLAKE2b-256 checksum How to use checksums |
2a72d4143c66c1806599358c119c0af530bab92ef0c48129f17522dfd5a7ff6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for pytest-regex 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.