pytest_reorder

Reorder tests depending on their nodeids (strings of test file path plus test name plus parametrization, like: test/test_prefix_reordering.py::test_reordering_default[test_names5-expected_test_order5]).
Normally tests are sorted alphabetically. That makes integration tests run before unit tests.
With pytest_reorder you can install a hook that will change the order of tests in the suite. By default pytest_reorder will seek for unit, integration and ui tests and put them in the following order:
unit
all tests with names not indicating unit, integration, nor UI tests
integration
ui
The default regular expressions can find unit, integration and UI tests both laid flat and deeply nested. You can also specify your custom order.
HOWTO
It’s possible to customize the ordering. To do so, you have to specify your custom tests order by passing a list of regular expresions that match tests’ nodeids. If more than one regex matches some test nodeid, the first one wins.
Command line interface
pytest_reorder hooks in a --reorder command line option that takes zero arguments or an ordering spec list.
If no arguments are given, default reordering will be applied.
If a list is passed, e.g. --reorder '(^|.*/)(test_)?unit' '*' '(^|.*/)(test_)?web', tests are reordered to go as the matches in the list do. Regular list items are treated as Python regexes. The special '*' match is required and specifies where to put tests that don’t match any of the regexes. A single asterisk was chosen for that because it’s not a valid regular expression.
Programmatic interface
Modify your main conftest file (e.g. tests/conftest.py) to include:
from pytest_reorder import default_reordering_hook as pytest_collection_modifyitems # add noqa here if you use pyflakes
or specify a custom test order:
from pytest_reorder import make_reordering_hook
# Make unit tests run before 'db' tests, which run before 'web' tests. Other tests will run at
# the very beginning of the suite:
pytest_collection_modifyitems = make_reordering_hook(
[None, r'(^|.*/)(test_)?unit', r'(^|.*/)(test_)?db', r'(^|.*/)(test_)?web'])
Without pytest_reorder
Flat:
sample_test_suites/flat/test_sample.py ...
sample_test_suites/flat/integration/test_some_integration.py ..
sample_test_suites/flat/ui/test_some_ui.py .
sample_test_suites/flat/unit/test_some_unit.py ..
Nested:
sample_test_suites/nested/app_1/tests/integration/test_some_integration.py ..
sample_test_suites/nested/app_1/tests/ui/test_some_ui.py .
sample_test_suites/nested/app_1/tests/unit/test_some_unit.py ..
sample_test_suites/nested/app_2/tests/test_sth.py ...
sample_test_suites/nested/app_2/tests/test_unit.py .
With pytest_reorder
Flat:
sample_test_suites/flat/unit/test_some_unit.py ..
sample_test_suites/flat/test_sample.py ...
sample_test_suites/flat/integration/test_some_integration.py ..
sample_test_suites/flat/ui/test_some_ui.py .
Nested:
sample_test_suites/nested/app_1/tests/unit/test_some_unit.py ..
sample_test_suites/nested/app_2/tests/test_unit.py .
sample_test_suites/nested/app_2/tests/test_sth.py ...
sample_test_suites/nested/app_1/tests/integration/test_some_integration.py ..
sample_test_suites/nested/app_1/tests/ui/test_some_ui.py .
Metadata
Release files for pytest-reorder 0.1.1
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_reorder-0.1.1.tar.gz | 5.9 kB | Without provenance | Details for pytest_reorder-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_reorder-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pytest_reorder-0.1.1-py3-none-any.whl |
Total release size: 11.5 kB
Release files / pytest_reorder-0.1.1.tar.gz
| Download URL | pytest_reorder-0.1.1.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
298f7c90d6d9a2d1bccf5775258b343e928df544e56a9be7e450bfca4fe09d7e
|
|
BLAKE2b-256 checksum How to use checksums |
7bf018e7606c7219665825d7baff768950b4c4e84cdfd5cff159f1aa5bcea90d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pytest_reorder-0.1.1-py3-none-any.whl
| Download URL | pytest_reorder-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1fca553ffb965e10192716208a94239a67ba2ffbe441c47665075ef7f1351500
|
|
BLAKE2b-256 checksum How to use checksums |
4d7e35dacdd38028efe9a575ac1d87ed31f39920940d84dd6094f70c3ae28301
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pytest-reorder 0.1.1
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.