Skip to main content

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-file option 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 @regexp suffix: 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-id and --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-file options to accept multiple, semicolon-separated files simultaneously
    • Introduced support for selecting/skipping parameter combinations with regular expressions using the @regexp syntax
    • Improved integration of simultaneous use of --select-from-file, --deselect-from-file, and --skip-from-file
  • v0.1.0 - 4/4/2025:

    • Initial release

Metadata

Release files for pytest-skip 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-skip 0.2.0
File Size Uploaded
pytest_skip-0.2.0.tar.gz 15.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-skip 0.2.0
File Interpreter ABI Platform
pytest_skip-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.9 kB

Release files / pytest_skip-0.2.0.tar.gz

Download URL pytest_skip-0.2.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0dded7d73da8aef3cb6a7c51b7f6181e7876d4406ceac8338d2d8889d2e451e2
BLAKE2b-256 checksum
How to use checksums
8e9726aeafc949fcb23b83d84af65cf578ef7f3396aa9adeb0f0cc47fe994a65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / pytest_skip-0.2.0-py3-none-any.whl

Download URL pytest_skip-0.2.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4003301886f32cb1feed76c0647e581bd15d7fec858f95824b5adf7d02c57534
BLAKE2b-256 checksum
How to use checksums
f13212870cd3afb2cad0cb99f6b8bc504c67cc532c9cd510d84d45793d872165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page