Skip to main content

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-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

Usage

This plugin adds new command line options to pytest:

  • --select-from-file
  • --deselect-from-file
  • --skip-from-file
  • --select-fail-on-missing

The first three expect an argument that resolves to a UTF-8 encoded text file containing one test name per line. Text file may contain blank and comment lines (starts from #),

The fourth 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.

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 selection.txt
test_something
test_parametrized[1]
test_parametrized
tests/test_foo.py::test_other

$~ pytest --select-from-file selection.txt
$~ pytest --deselect-from-file selection.txt
$~ pytest --skip-from-file selection.txt

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.1.0 - 4/4/2025:
    • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_skip-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_skip-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_skip-0.1.1.tar.gz.

File metadata

  • Download URL: pytest_skip-0.1.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_skip-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d443cca954c7ac48f8dbe4c8271297e5a45d865a73d6c3da5bb31213a8ab7b58
MD5 a72683063ce81cf2f6bf944f532ce487
BLAKE2b-256 955e485014cd3939346a8eafede665eac06186b84bc68dae680be6c40c91f522

See more details on using hashes here.

File details

Details for the file pytest_skip-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_skip-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_skip-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 21f84f741f864e59b2a07f963afa67dbd69bafd019134b8c6e6091e4a90e4e20
MD5 20c2b62c4b3daed09b649a3ba248f4e4
BLAKE2b-256 79d34584e0d50fdd38ae07e93b69a069ce0a9d12a71455c0015bbcbd1ca69528

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page