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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_missing_modules-0.2.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_missing_modules-0.2.2.tar.gz
  • Upload date:
  • Size: 98.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_missing_modules-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d23252e1d5f9e4dff1b58448e5d70cc66aa209258338e7c006756af412cafd45
MD5 9e7a8e4ba94d1a39b4c965ca5a25168a
BLAKE2b-256 8a91d3f4a045170269e3491a49946e9c824cfcc8d2303c83521c86f11fa422a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_missing_modules-0.2.2.tar.gz:

Publisher: publish.yml on jeertmans/pytest-missing-modules

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pytest_missing_modules-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b95797ecb3b6af72c9f634a1c40c043a5f4b78aef5292e5d8dc2cbb7ed5f491b
MD5 2f77d301395825d4346426204db8711e
BLAKE2b-256 36978634f8bc5cfb899c53f13748e68fa5bb374dd8f6381c09bd3384c7233dd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_missing_modules-0.2.2-py3-none-any.whl:

Publisher: publish.yml on jeertmans/pytest-missing-modules

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page