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.1.tar.gz
.
File metadata
- Download URL: pytest_missing_modules-0.2.1.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 | 747a6acb975904c79d26410f0e0119cfcf6144cfdc5c2a70cc1f0955a57458e1 |
|
MD5 | 32bb47e26a5cc5764e9265ae6a7955c1 |
|
BLAKE2b-256 | 49695161e1cf918baccdac65db7cbef78e1cfe29ee3b83fcb4a2f3568d8573a0 |
File details
Details for the file pytest_missing_modules-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: pytest_missing_modules-0.2.1-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 | ad8827b4ab01049dd552bbd2875b844dacb1e6c61e01d216f90f566e9096d14b |
|
MD5 | 429fa57e4fc9e9faa798455fd5c6e123 |
|
BLAKE2b-256 | 585540d10c08a8e77d9ee549dfaa75d0056b4328374956e124cbdd4b77b73f78 |