Skip to main content

A minimal library for writing tests with optional dependencies.

Project description

Needy logo

CI Coverage PyPI Python License

Needy

A tiny library for writing tests that depend on optional packages, without having everything crash when a package you need is just not there…

Installation

Python 3.11+ is required.

pip install pyneedy  # needy was already taken ( ╥_╥)

Quick Start

Define a probe for the optional dependency you want to use, like JAX:

def jax_module() -> None:
    import jax as jax

Then just mark the tests that need it with @needs.to_run(...):

from needy import needs


@needs.to_run(jax_module)
def test_that_uses_jax() -> None:
    import jax.numpy as jnp

    assert jnp.array([1.0, 2.0]).sum() == 3.0

If jax is installed, the test runs. If it isn't, the test is just skipped instead of crashing the whole suite. Yay!

For optional imports at the top of a file (which would normally fail at collection time), use needs.modules(...). See the docs for more.

Documentation

Getting started The basics: probes and @needs.to_run(...)
Optional imports Handle missing modules at import time with needs.modules
Subtests Mix required and optional paths in one test
API reference Every type and function in one place

Development

Prerequisites:

  • Python >= 3.11
  • uv (recommended) or pip
  • just (optional, for convenience)

Get set up:

git clone https://gitlab.com/pytooling/needy.git
cd needy
uv sync
uv run pre-commit install

Run all checks (lint, format, type-check, tests):

just check

Or manually:

uv run ruff check --fix && uv run ruff format && uv run pyright && uv run pytest

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

pyneedy-1.2.0.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

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

pyneedy-1.2.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pyneedy-1.2.0.tar.gz.

File metadata

  • Download URL: pyneedy-1.2.0.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyneedy-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7defbdb661b6f973d54ac5e09ba1dfdbfd40f18cd8cda0f80b946c20ceb2acf6
MD5 d040ba3710be1cbd2a5b74a58f7edff5
BLAKE2b-256 062174fc11e4fce5e74cf65bb5df5daccf0c61993db1e1064346b2eadf726606

See more details on using hashes here.

File details

Details for the file pyneedy-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyneedy-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyneedy-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a9dc494b9aca96d6c9ee1a65bdd26b7fab198148cfae271edb4c3b2f880c9c7
MD5 bdc8152c7e8330714985edb6dc0c34f4
BLAKE2b-256 ccbcdca2a7c44a0700d77830987616fcf62e3a930ed27b72b5b60d1ecea28b17

See more details on using hashes here.

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