pytest-missing-modules

Pytest plugin for faking missing modules

MIT License

Downloads
3.8K
Stars
0

pytest-missing-modules

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.
Package Rankings
Top 34.56% on Pypi.org
Badges
Extracted from project README
Latest Release Python version Documentation
Related Projects