Skip to main content

Easy declaration of optional tests (i.e., that are not run by default)

Project description

PyPI version Python versions See Build Status on Travis CI

Provides easy declaration of optional tests using pytest markers. Optional tests are run only on request via the config file or command line.


Motivation

Some classes of tests should not be run with every test invocation. It is often useful to define tests that be run only when specifically requested, such as tests that are slow, require network access, or work only in certain environments.

Pytest provides mechanisms to run tests based on test names (-k) and to filter tests based on markers (-m). Neither mechanism makes it easy to surpress certain tests by default. For example, one might decorate tests with @pytest.mark.network, but disabling it by default requires a marker expression like -m “not network” with every invocation. Markers and marker expressions become unwieldy when there are many markers.

This plugin enables users to declare that certain markers are “optional markers”. When tests are decorated with an optional marker, the test is skipped by default. Tests may be decorated with multiple markers, including multiple optional markers. Optional tests may be enabled in the pytest ini file or the command line.

Installation

You can install “pytest-optional-tests” via pip from PyPI:

$ pip install pytest-optional-tests

Usage

Optional markers must be declared in inicfg using the same syntax as the markers option. For example:

[pytest]
optional_tests:
  slow: slow tests
  network: network tests
  bug: regression tests against previous bugs

Optional markers should NOT be declared using the markers attribute, even when using pytest’s strict mode.

Optional test decorators are pytest markers, and the semantics are identical.

If a test is decorated with multiple optional markers, the test will be executed when any of the markers is requested. For example:

@pytest.mark.network
@pytest.mark.slow
def test_slow_network_function(): ...

will be tested if either or both of the optional slow or network tests are requested.

Optional tests may be requested in the inicfg:

[pytest]
optional_tests:
  slow: slow tests
  network: network tests
  bug: regression tests against previous bugs
run_optional_tests=network,slow

or on the command line:

pytest --run-option-tests=network,slow

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license.

Issues

If you encounter any problems, please file an issue along with a detailed description.

This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

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-optional-tests-0.1.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

pytest_optional_tests-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-optional-tests-0.1.1.tar.gz.

File metadata

  • Download URL: pytest-optional-tests-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for pytest-optional-tests-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7f4411bf1551b556ae24a7e1385c4832d7520ccef109c374929aa71afe8c6754
MD5 e9fba2b9d28425bce70916c5f36991e2
BLAKE2b-256 b30de0ed3c137ac8b604d0a90aa4a23e50ef21a66320b50a6a9b2c5f41e5a986

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_optional_tests-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for pytest_optional_tests-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ededc9d2aa7051d1af8ff5e757119b5758d86c7f24e73e1bb7dd5f19cd2031fa
MD5 2dd71448a873e85c4aec0cf39283e920
BLAKE2b-256 f24a7726bed4f1fda2f4af35d1b8d774169aa0103f0141abe3fb3ba7761efa86

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