# 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_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:
```python
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](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/
Raw data
{
"_id": null,
"home_page": null,
"name": "pytest-missing-modules",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "missing, mocking, modules, plugin, pytest, testing",
"author": null,
"author_email": "J\u00e9rome Eertmans <jeertmans@icloud.com>",
"download_url": "https://files.pythonhosted.org/packages/49/69/5161e1cf918baccdac65db7cbef78e1cfe29ee3b83fcb4a2f3568d8573a0/pytest_missing_modules-0.2.1.tar.gz",
"platform": null,
"description": "# pytest-missing-modules\n\n[![Latest Release][pypi-version-badge]][pypi-version-url]\n[![Python version][pypi-python-version-badge]][pypi-version-url]\n[![Documentation][documentation-badge]][documentation-url]\n\nMinimalist Pytest plugin that adds a fixture to fake missing modules.\n\n## Who should use this plugin\n\nSometimes, your code needs to handle the possibility that\nan optional dependency can be *missing*, e.g., you develop a plotting\nlibrary supporting multiple drawing backends.\n\nThis plugin provides a convenient way to simulate one\nor multiple missing modules, raising an `ImportError` instead.\n\n## Usage\n\nFirst, install this plugin with:\n\n```bash\npip install pytest-missing-modules\n```\n\nThen, you use the Pytest fixtures like so:\n\n```python\n# this should be in one of your test files\nimport importlib\nimport my_package\n\n\ndef test_missing_numpy(missing_modules):\n with missing_modules(\"numpy\"):\n # Check that you can still import your package, without NumPy!\n importlib.reload(my_package)\n```\n\nIf you need, you can also add type hints to your code:\n\n```python\nfrom pytest_missing_modules.plugin import MissingModulesContextGenerator\n\n\ndef test_missing_package(missing_modules: MissingModulesContextGenerator):\n # your test logic goes here\n```\n\nFor more advance usage, please check the\n[documentation](https://pytest-missing-modules.readthedocs.io/).\n\n## Contributing\n\nThis project welcomes any contribution, and especially:\n\n+ bug fixes;\n+ or documentation typos.\n\n[pypi-version-badge]: https://img.shields.io/pypi/v/pytest-missing-modules?label=pytest-missing-modules\n[pypi-version-url]: https://pypi.org/project/pytest-missing-modules/\n[pypi-python-version-badge]: https://img.shields.io/pypi/pyversions/pytest-missing-modules\n[pypi-download-badge]: https://img.shields.io/pypi/dm/pytest-missing-modules\n[documentation-badge]: https://readthedocs.org/projects/pytest-missing-modules/badge/?version=latest\n[documentation-url]: https://pytest-missing-modules.readthedocs.io/\n",
"bugtrack_url": null,
"license": null,
"summary": "Pytest plugin to easily fake missing modules",
"version": "0.2.1",
"project_urls": {
"Changelog": "https://github.com/jeertmans/pytest-missing-modules/releases",
"Documentation": "https://github.com/jeertmans/pytest-missing-modules",
"Founding": "https://github.com/sponsors/jeertmans",
"Homepage": "https://github.com/jeertmans/pytest-missing-modules",
"Repository": "https://github.com/jeertmans/pytest-missing-modules"
},
"split_keywords": [
"missing",
" mocking",
" modules",
" plugin",
" pytest",
" testing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "585540d10c08a8e77d9ee549dfaa75d0056b4328374956e124cbdd4b77b73f78",
"md5": "429fa57e4fc9e9faa798455fd5c6e123",
"sha256": "ad8827b4ab01049dd552bbd2875b844dacb1e6c61e01d216f90f566e9096d14b"
},
"downloads": -1,
"filename": "pytest_missing_modules-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "429fa57e4fc9e9faa798455fd5c6e123",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5536,
"upload_time": "2024-09-03T10:05:29",
"upload_time_iso_8601": "2024-09-03T10:05:29.498800Z",
"url": "https://files.pythonhosted.org/packages/58/55/40d10c08a8e77d9ee549dfaa75d0056b4328374956e124cbdd4b77b73f78/pytest_missing_modules-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "49695161e1cf918baccdac65db7cbef78e1cfe29ee3b83fcb4a2f3568d8573a0",
"md5": "32bb47e26a5cc5764e9265ae6a7955c1",
"sha256": "747a6acb975904c79d26410f0e0119cfcf6144cfdc5c2a70cc1f0955a57458e1"
},
"downloads": -1,
"filename": "pytest_missing_modules-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "32bb47e26a5cc5764e9265ae6a7955c1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 10192,
"upload_time": "2024-09-03T10:05:30",
"upload_time_iso_8601": "2024-09-03T10:05:30.446250Z",
"url": "https://files.pythonhosted.org/packages/49/69/5161e1cf918baccdac65db7cbef78e1cfe29ee3b83fcb4a2f3568d8573a0/pytest_missing_modules-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-03 10:05:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jeertmans",
"github_project": "pytest-missing-modules",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pytest-missing-modules"
}