Skip to main content

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.

Release files for pyneedy 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyneedy 1.4.0
File Size Uploaded
pyneedy-1.4.0.tar.gz 58.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyneedy 1.4.0
File Interpreter ABI Platform
pyneedy-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 71.6 kB

Release files / pyneedy-1.4.0.tar.gz

Download URL pyneedy-1.4.0.tar.gz
Size 58.1 kB
Tags Source
SHA-256 checksum
How to use checksums
360285439c9f7d12bda445834734224a7a7f3d508d41d48edcbe62f51f8fa03e
BLAKE2b-256 checksum
How to use checksums
fc75cd7e3b8e6ccf2eaa6931fba6b9d9c4bd5a6f8503bdaeda9b74bab68ce4fe
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / pyneedy-1.4.0-py3-none-any.whl

Download URL pyneedy-1.4.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9154f3fc61572efd9aee0abff728f916dd804784cdcacb56373a4911d1c6145
BLAKE2b-256 checksum
How to use checksums
01ed251e31a5bd454328d1548b7a21c530a98ef7a19c92060c0aa59012e4c2ed
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page