Skip to main content

A pytest plugin which allows to (de-)select tests from a file.

Project description

PyPI pyversions PyPI license PyPI version CircleCI build Codecov result

This is a pytest plugin which allows to (de-)select tests by name from a list loaded from a file.


It’s recommended to install this package from PyPI:

pip install pytest-select


This plugin adds new command line options to pytest:

  • --select-from-file

  • --deselect-from-file

  • --select-fail-on-missing

The first two both expect an argument that resolves to a UTF-8 encoded text file containing one test name per line.

The third one changes the behaviour in case (de-)selected 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. are accepted.


$~ cat selection.txt

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


This package uses Poetry. To setup a development environment install Poetry and then run:

poetry install


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.

What is this useful for

The author uses this plugin to split tests across workers on Circle CI.


pytest --collect-only --quiet | \
    grep '::' | \
    circleci tests split --split-by=timings --timings-type=testname > selected.txt
pytest --select-from-file selected.txt

Version History

  • v0.1.2 - 2019-01-18:
    • Add informational pytest header report output

  • v0.1.1 - 2018-12-10:
    • Add --select-fail-on-missing option

    • Add basic mutation testing

  • v0.1.0post0 - 2018-12-08:
    • Fix README

  • v0.1.0 - 2018-12-08:
    • 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-select-0.1.2.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

pytest_select-0.1.2-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

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