Skip to main content

Pytest plugin to easily fake missing modules

Project description

pytest-missing-modules

Latest Release Python version Documentation

Minimalist Pytest plugin that adds a fixture to fake missing modules.

Who should use this plugin

Sometimes, your code needs to handle the possibility that an optional dependency can be missing, e.g., you develop a plotting library supporting multiple drawing backends.

This plugin provides a convenient way to simulate one or multiple missing modules, raising an ImportError instead.

Usage

First, install this plugin with:

pip install pytest-missing-modules

Then, you use the Pytest fixtures like so:

# this should be in one of your test files
import importlib
import my_package


def test_missing_numpy(missing_modules):
    with missing_modules("numpy"):
        # Check that you can still import your package, without NumPy!
        importlib.reload(my_package)

If you need, you can also add type hints to your code:

from pytest_missing_modules.plugin import MissingModulesContextGenerator


def test_missing_package(missing_modules: MissingModulesContextGenerator):
    # your test logic goes here

For more advance usage, please check the documentation.

Contributing

This project welcomes any contribution, and especially:

  • bug fixes;
  • or documentation typos.

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_missing_modules-0.2.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

pytest_missing_modules-0.2.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_missing_modules-0.2.1.tar.gz.

File metadata

File hashes

Hashes for pytest_missing_modules-0.2.1.tar.gz
Algorithm Hash digest
SHA256 747a6acb975904c79d26410f0e0119cfcf6144cfdc5c2a70cc1f0955a57458e1
MD5 32bb47e26a5cc5764e9265ae6a7955c1
BLAKE2b-256 49695161e1cf918baccdac65db7cbef78e1cfe29ee3b83fcb4a2f3568d8573a0

See more details on using hashes here.

File details

Details for the file pytest_missing_modules-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_missing_modules-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad8827b4ab01049dd552bbd2875b844dacb1e6c61e01d216f90f566e9096d14b
MD5 429fa57e4fc9e9faa798455fd5c6e123
BLAKE2b-256 585540d10c08a8e77d9ee549dfaa75d0056b4328374956e124cbdd4b77b73f78

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