Skip to main content

Pytest plugin to easily fake missing modules

Project description

pytest-missing-modules

Latest Release Python version

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


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

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.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

pytest_missing_modules-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for pytest_missing_modules-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0a585d4860ae17b3f4401642180f7537180af62d70483e2db370e3ae68226c3
MD5 ef269cce0eed6ebd74ffc4353403c138
BLAKE2b-256 6db1a4b71a43aab8fccae0933d24777beecae6f11ef39ee05000790353cf8d42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_missing_modules-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd9d9ab7f253de4783d022f7c3e258fe9d5815a59854c4cf2372475199aaa36
MD5 ac46971d64c4dcc2668fe75a70871c0a
BLAKE2b-256 4b327c583b25c2d39c41882a65db5003405f0c4c01384bb9e8a739a813a5ce87

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