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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-select-0.1.2.tar.gz
  • Upload date:
  • Size: 4.3 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.2.tar.gz
Algorithm Hash digest
SHA256 146aaaf294034f64cc0326448d04c03fa53df197248c9874712f21a919ce414e
MD5 338c56bb6f8361b2b09375c18e9ba9f0
BLAKE2b-256 74b6e9b6115204789b476aee3e7f8993d4e70c73f37f44379f555bcd83b1a63c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_select-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd4068204397efe8fcaa50f63305956f80a8ac90f4620888b7c46ebc3b00027b
MD5 ee88d14c847eca34acd5ee97aba1398b
BLAKE2b-256 03c6f07fbbefda11038f14607d1f1ba80f9e8bdaae1a291dee04db8514b481fb

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