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

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

Usage

This plugin adds two comamnd line options to pytest:

  • –select-from-file

  • –deselect-from-file

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

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]
tests/test_foo.py::test_other

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

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.

What is this useful for

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

Example:

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

Version History

  • 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.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

pytest_select-0.1.0-py3-none-any.whl (5.6 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