Skip to main content

A pytest plugin to elegantly skip tests with optional requirements

Project description

pytest-requires

PyPI version

Python versions

Build status

A pytest plugin to elegantly skip tests with optional requirements


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

Features

  • decorate tests that require optional modules (with an optional minimum version) and gracefully skip them when the requirements aren't importable

Requirements

  • pytest

Installation

You can install "pytest-requires" via pip from PyPI:

pip install pytest-requires

Usage

How to use pytest-requires

With pytest-requires, tests can be marked as requiring an external module as follows:

@pytest.mark.requires("dateutil")
def test_date_parsing():
    assert date_parsing() == RESULT

In this example if the python-dateutil module isn't installed the test is skipped. The import testing is all performed by pytest's builtin importorskip function.

Notes:

  • the minversion keyword can be given to specifiy a minimum acceptable version for the required module
  • multiple modules can be given as positional arguments, with the decorated tested being skipped if any of the given modules cannot be imported
  • in the case of multiple modules, only a single minversion can be given, and will be used for all modules; if an independent minversion is required for each module, use multiple @pytest.mark.requires decorators.

Why not just use pytest.importorskip?

pytest.importorskip is designed to import a module and add the module to the namespace (of the module, or the test function). If the optional module isn't used in the test itself, but is really a requirement of the function being tested, the call to importorskip less elegant (in the author's opinion) than a decorator call.

Contributing

Contributions are very welcome, please open a Pull Request.

License

Distributed under the terms of the MIT license, "pytest-requires" is free and open source software

Issues

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

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-requires-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

pytest_requires-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest-requires-0.1.0.tar.gz.

File metadata

  • Download URL: pytest-requires-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pytest-requires-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1d7ee62cffcd4d6ba16d21e5f96fc6d9006ef94f923d64e278d8b5fddbec924e
MD5 e63655e631adf8fcdd8063c01a38cdee
BLAKE2b-256 abfc2fc8d97d40b3bb74d93ba7baf06644f2e53daf31345721b5548acb2123e8

See more details on using hashes here.

File details

Details for the file pytest_requires-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_requires-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pytest_requires-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f13f3a7dd2d1f0df4affd2873719d0836f27012cea1a04efe6c7c117d4ec53cf
MD5 824e1d86a116ff2eec84af1924c96916
BLAKE2b-256 2ebf551afa01bc600ba472489a2269f87a8396424d965b864415a41494c541bd

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