Pytest plugin to easily fake missing modules
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest_missing_modules-0.2.0.tar.gz
.
File metadata
- Download URL: pytest_missing_modules-0.2.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 797e08a30ffa2d2b35003e71869b74d3cb4ecbbc73d3ad8238250a4ae2b2f9ec |
|
MD5 | 9efaffd77f3aea291861103643531ef2 |
|
BLAKE2b-256 | b1c170653886561f4eef9307cc8b3af9d162fcadd13c790d24bdbc63ebd38c18 |
File details
Details for the file pytest_missing_modules-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_missing_modules-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3362440bf0dec002f3295d82f579aa182f6bc5116bdcc0dc7bc2d7b0c07c87e |
|
MD5 | c654e965031ca97b6226205f17d7c503 |
|
BLAKE2b-256 | 48baec203b498410ed8a922cf2514640232113df573e1113534e5eed14e21c09 |