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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for pytest_missing_modules-0.2.0.tar.gz
Algorithm Hash digest
SHA256 797e08a30ffa2d2b35003e71869b74d3cb4ecbbc73d3ad8238250a4ae2b2f9ec
MD5 9efaffd77f3aea291861103643531ef2
BLAKE2b-256 b1c170653886561f4eef9307cc8b3af9d162fcadd13c790d24bdbc63ebd38c18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_missing_modules-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3362440bf0dec002f3295d82f579aa182f6bc5116bdcc0dc7bc2d7b0c07c87e
MD5 c654e965031ca97b6226205f17d7c503
BLAKE2b-256 48baec203b498410ed8a922cf2514640232113df573e1113534e5eed14e21c09

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