Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeertmans/pytest-missing-modules
Pytest plugin for faking missing modules
https://github.com/jeertmans/pytest-missing-modules
Last synced: 30 days ago
JSON representation
Pytest plugin for faking missing modules
- Host: GitHub
- URL: https://github.com/jeertmans/pytest-missing-modules
- Owner: jeertmans
- License: mit
- Created: 2024-08-26T13:04:17.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-03T10:04:44.000Z (3 months ago)
- Last Synced: 2024-10-03T16:21:35.478Z (about 2 months ago)
- Language: Python
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# pytest-missing-modules
[![Latest Release][pypi-version-badge]][pypi-version-url]
[![Python version][pypi-python-version-badge]][pypi-version-url]
[![Documentation][documentation-badge]][documentation-url]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:
```bash
pip install pytest-missing-modules
```Then, you use the Pytest fixtures like so:
```python
# this should be in one of your test files
import importlib
import my_packagedef 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:
```python
from pytest_missing_modules.plugin import MissingModulesContextGeneratordef test_missing_package(missing_modules: MissingModulesContextGenerator):
# your test logic goes here
```For more advance usage, please check the
[documentation](https://pytest-missing-modules.readthedocs.io/).## Contributing
This project welcomes any contribution, and especially:
+ bug fixes;
+ or documentation typos.[pypi-version-badge]: https://img.shields.io/pypi/v/pytest-missing-modules?label=pytest-missing-modules
[pypi-version-url]: https://pypi.org/project/pytest-missing-modules/
[pypi-python-version-badge]: https://img.shields.io/pypi/pyversions/pytest-missing-modules
[pypi-download-badge]: https://img.shields.io/pypi/dm/pytest-missing-modules
[documentation-badge]: https://readthedocs.org/projects/pytest-missing-modules/badge/?version=latest
[documentation-url]: https://pytest-missing-modules.readthedocs.io/