A pytest plugin which allows to (de-)select or skip tests from a file.
Project description
pytest-skip
This is a pytest plugin which allows to (de-)select or skip tests by name from a list loaded from a file.
pytest-skip expands upon the capabilities of the original pytest-select plugin by adding
--skip-from-fileoption to skip tests instead of deselecting- support to (de-)select or skip parametrized tests without needing to specify test instance qualifiers
- support for blank and comment lines in the selection files
- better integration with the
pytest-xdist, plugin warning and error messages are passed to the master node with proper stdout or stderr outputs - sharding functionality to distribute tests across several nodes
- an ability to select/skip parameters combinations matching a certain regular expression.
Put your regexp in the square brackets as a raw string and end the line with
@regexpsuffix:file.py::test[r"REGEXP"]@regexp
Usage
This plugin adds new command line options to pytest:
--select-from-file--deselect-from-file--skip-from-file--select-test--deselect-test--skip-from-test--select-fail-on-missing--num-shards,--shard-idand--sharding-mode
The first three expect an argument that resolves to one or multiple, semicolon-separated, UTF-8 encoded text file(s)
containing one test name per line. Text file may contain blank and comment lines (starts from #). All three
(select, deselect, skip) options can be used simultaneously.
The next three expect one or multiple, semicolon-separated, test names to be selected, deselected or skipped.
The next one changes the behaviour in case (de-)selected or skipped test names are missing from the to-be executed tests.
By default a warning is emitted and the remaining selected tests are executed as normal.
By using the --select-fail-on-missing flag this behaviour can be changed to instead abort execution in that case.
The sharding parameters allow users to split the test sets into even portions across multiple shards for parallel execution. The tests that are filtered out for a shard will be deselected.
Test names are expected in the same format as seen in the output of
pytest --collect-only --quiet for example.
Both plain test names or complete node ids (e.g. test_file.py::test_name) are accepted.
Example::
$~ cat select.txt
test_something
test_parametrized[1]
test_parametrized
tests/test_foo.py::test_other
test_parametrized_complex[r"[8|16]-.*-.*"]@regexp
tests/test_foo.py::test_params[r"int32-.*-.*"]@regexp
$~ cat deselect.txt
tests/test_foo.py::test_params[r"bf32-.*-.*"]@regexp
$~ cat skip1.txt
test_parametrized[1]
test_parametrized[2]
$~ cat skip2.txt
test_parametrized[r"[579]"]@regexp
$~ pytest --select-from-file select.txt
$~ pytest --deselect-from-file deselect.txt
$~ pytest --select-from-file select.txt --deselect-from-file deselect.txt --skip-from-file skip1.txt:skip2.txt
$~ pytest --skip-from-file skip1.txt:skip2.txt --num-shards=4 --shard-id=0 --sharding-mode=round-robin
$~ pytest --skip-from-file skip1.txt:skip2.txt --num-shards=4 --shard-id=0 --sharding-mode=contiguous-split
Install from source
git clone --recursive https://github.com/vlad-penkin/pytest-skip
# Run this command from the pytest-skip directory after cloning the source code using the command above
pip install .
Install in development mode
To install plugin in development mode run::
pip install -e .
Questions
Why not use pytest's builtin -k option
The -k selection mechanism is (currently) unable to deal with selecting multiple parametrized
tests and is also a bit fragile since it matches more than just the test name.
Additionally, depending on the number of tests, giving test names on the command line can overflow
the maximum command length.
Version History
-
v0.2.0- 9/12/2025:- Added sharding functionality (
--num-shards,--shard-id,--sharding-mode) to distribute tests across multiple nodes - Added ability to (de-)select or skip tests directly by name (
--select-test,--deselect-test,--skip-test) - Extended
--*-from-fileoptions to accept multiple, semicolon-separated files simultaneously - Introduced support for selecting/skipping parameter combinations with regular expressions using the
@regexpsyntax - Improved integration of simultaneous use of
--select-from-file,--deselect-from-file, and--skip-from-file
- Added sharding functionality (
-
v0.1.0- 4/4/2025:- Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_skip-0.2.0.tar.gz.
File metadata
- Download URL: pytest_skip-0.2.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dded7d73da8aef3cb6a7c51b7f6181e7876d4406ceac8338d2d8889d2e451e2
|
|
| MD5 |
6291d5478b7d75526454c4f65ac90bc8
|
|
| BLAKE2b-256 |
8e9726aeafc949fcb23b83d84af65cf578ef7f3396aa9adeb0f0cc47fe994a65
|
File details
Details for the file pytest_skip-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pytest_skip-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4003301886f32cb1feed76c0647e581bd15d7fec858f95824b5adf7d02c57534
|
|
| MD5 |
c85677c29a85019848ee7b054f8fadf5
|
|
| BLAKE2b-256 |
f13212870cd3afb2cad0cb99f6b8bc504c67cc532c9cd510d84d45793d872165
|