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.

Installation

It’s recommended to install this package from PyPI:

pip install pytest-select

Usage

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

Development

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

poetry install

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 --timings-type=testname > selected.txt
pytest --select-from-file selected.txt

Version History

  • 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.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

pytest_select-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest-select-0.1.1.tar.gz.

File metadata

  • Download URL: pytest-select-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.10 CPython/3.6.4 Darwin/18.2.0

File hashes

Hashes for pytest-select-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5ea19315b394c8c7808528cfadc2257d4e1a4ab9983bd4cb2ecb67bb045d7ebc
MD5 193aad1042b1fa86bf60eaaa7141abf8
BLAKE2b-256 5e5f1d761318c1c5d07e83e37e30ed2ac31ce8e599c57d686ac504a84b8cb199

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_select-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.10 CPython/3.6.4 Darwin/18.2.0

File hashes

Hashes for pytest_select-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9f6efd8101262d0eabbc4ffcb6f4e1b67a174e4f3b572486919209324e13d84b
MD5 e7d491d9987796ce879d19ff1952f9bf
BLAKE2b-256 913e7d1733457c7ff640bc6b26ffd8c3e4ab2cd76b3a9d6a9d5eefe028344733

See more details on using hashes here.

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