Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_optional_dependencies-0.1.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_optional_dependencies-0.1.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_optional_dependencies-0.1.2.tar.gz.

File metadata

File hashes

Hashes for pytest_optional_dependencies-0.1.2.tar.gz
Algorithm Hash digest
SHA256 eb5857d3b11eb18e227b3c639507b6d68d306d9a90379b13df834887e8108e81
MD5 00e59726a13a78eb3358899a9d870dda
BLAKE2b-256 7038a582b81d434591ea8a8b4aad2723429a9a63bd39a17af18ddd0bf4120df0

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_optional_dependencies-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_optional_dependencies-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c65116a38d56dffb70b9de1a24784a5dc4f6fc8cef50078fb438a9c7c469f49f
MD5 25ef5446705f0739083f81160859d635
BLAKE2b-256 079814ea1e3b4e2f9788d12e1a7439445319a04cb8cb470a332faeb3b271ac70

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page