A minimal library for writing tests with optional dependencies.
Project description
Needy
A minimal library for writing tests with optional dependencies.
Installation
Python 3.11+ is required.
pip install pyneedy
Quick Start
Define "probes" for the optional dependencies you want to use, e.g. JAX.
class check:
@staticmethod
def jax() -> None:
# A probe just tries to import the optional dependency.
import jax as jax
Then wrap imports related to the optional dependency in a needs.modules(...) scope like this:
from needy import needs
from pytest import mark
with needs.modules(check.jax):
import jax.numpy as jnp
@mark.parametrize(
["array", "expected_sum"],
[
(
array := jnp.array([1.0, 2.0]),
expected_sum := 3.0
),
(
array := jnp.array([]),
expected_sum := 0.0
)
]
)
def test_that_a_sum_is_computed(array, expected_sum) -> None:
assert array.sum() == expected_sum
If jax is installed, the imports inside the with block resolve normally. If it isn't, every missing import inside the block is replaced with a proxy, and only the first real use of the missing modules will raise an error.
See the docs for more.
Development
Prerequisites
Getting Started
-
Clone the repository:
git clone https://gitlab.com/pytooling/needy.git cd needy
-
Create a virtual environment and install dependencies:
uv sync -
Install pre-commit hooks:
uv run pre-commit install
Running Checks
just check
Or manually:
uv run ruff check --fix && uv run ruff format && uv run pyright && uv run pytest
License
This project is licensed under the MIT License. See LICENSE for details.
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
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 pyneedy-1.0.0.tar.gz.
File metadata
- Download URL: pyneedy-1.0.0.tar.gz
- Upload date:
- Size: 5.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac3976f29edd18be41dac46b48933596000e1823e6d96d1296fb6c94e8f744fb
|
|
| MD5 |
524f4a9c9cbf1abfee3e3d7eaf489459
|
|
| BLAKE2b-256 |
8b640be431cd479e83dd1a8ac1c01c526a32b05d4ca7f528476069068f54e68c
|
File details
Details for the file pyneedy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyneedy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3a726ae6d46a6777416ddabf5b5c9ad2b9730e268c85c9d24a1ebcec3463fd4
|
|
| MD5 |
3abd86842ac2e72e4e8e272882749def
|
|
| BLAKE2b-256 |
00fca96fb4c8edc54178e43ce6b03d2c49d1b87088980da182b8bd57b2276874
|