Don't test code that won't load due to missing imports. A pytest plugin to skip tests that require optional dependencies that are not installed.
Project description
pytest-optional-dependencies
Don't test code that won't load due to missing imports. A pytest plugin to skip tests that require optional dependencies that are not installed.
Collection-time optional dependency handling for pytest.
This plugin allows specific missing imports to be treated as optional so collection can continue without errors.
Features
- --optional-dependency MODULE (repeatable, also accepts comma-separated values).
- specify which dependencies to skip/deselect based on their absence
- --optional-dependencies-any
- to treat any missing module import as optional.
- --optional-dependencies-action
- to control optional import handling: skip (default) or deselect.
- Configuration options
- optional_dependencies
- optional_dependencies_any
- optional_dependencies_action
- --report-optional-dependencies
- Report what was filtered and why.
Install
uv pip install pytest-optional-dependencies
Or with pip:
python -m pip install pytest-optional-dependencies
Compatibility
- Python: 3.10+
- pytest: 8.0+
CLI options
- --optional-dependency MODULE
- --optional-dependencies-any
- --optional-dependencies-action {deselect,skip}
- --report-optional-dependencies
Configuration
pytest.ini:
[pytest]
optional_dependencies =
optional_dependency
some_namespace.submodule
optional_dependencies_any = false
optional_dependencies_action = skip
pyproject.toml:
[tool.pytest.ini_options]
optional_dependencies = [
"optional_dependency",
"some_namespace.submodule",
]
optional_dependencies_any = false
optional_dependencies_action = "skip"
Example
pytest -q --optional-dependency optional_dependency --report-optional-dependencies
pytest -q --optional-dependency optional_dependency --optional-dependencies-action skip
Development
python -m pytest -q
License
MIT. See LICENSE.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_optional_dependencies-0.1.2.tar.gz.
File metadata
- Download URL: pytest_optional_dependencies-0.1.2.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb5857d3b11eb18e227b3c639507b6d68d306d9a90379b13df834887e8108e81
|
|
| MD5 |
00e59726a13a78eb3358899a9d870dda
|
|
| BLAKE2b-256 |
7038a582b81d434591ea8a8b4aad2723429a9a63bd39a17af18ddd0bf4120df0
|
Provenance
The following attestation bundles were made for pytest_optional_dependencies-0.1.2.tar.gz:
Publisher:
publish-to-pypi.yml on okken/pytest-optional-dependencies
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_optional_dependencies-0.1.2.tar.gz -
Subject digest:
eb5857d3b11eb18e227b3c639507b6d68d306d9a90379b13df834887e8108e81 - Sigstore transparency entry: 2030144416
- Sigstore integration time:
-
Permalink:
okken/pytest-optional-dependencies@295c96b7dae393dc28ce336de2a1c7887ee8a736 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/okken
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@295c96b7dae393dc28ce336de2a1c7887ee8a736 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_optional_dependencies-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pytest_optional_dependencies-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c65116a38d56dffb70b9de1a24784a5dc4f6fc8cef50078fb438a9c7c469f49f
|
|
| MD5 |
25ef5446705f0739083f81160859d635
|
|
| BLAKE2b-256 |
079814ea1e3b4e2f9788d12e1a7439445319a04cb8cb470a332faeb3b271ac70
|
Provenance
The following attestation bundles were made for pytest_optional_dependencies-0.1.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on okken/pytest-optional-dependencies
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_optional_dependencies-0.1.2-py3-none-any.whl -
Subject digest:
c65116a38d56dffb70b9de1a24784a5dc4f6fc8cef50078fb438a9c7c469f49f - Sigstore transparency entry: 2030144566
- Sigstore integration time:
-
Permalink:
okken/pytest-optional-dependencies@295c96b7dae393dc28ce336de2a1c7887ee8a736 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/okken
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@295c96b7dae393dc28ce336de2a1c7887ee8a736 -
Trigger Event:
push
-
Statement type: