pytest-predicate
pytest-predicate provides pytest integration for py-predicate.
It includes assertion helpers and fixtures for testing predicates with examples that should match or not match.
Installation
pip install pytest-predicate
The package installs a pytest plugin automatically through the pytest11 entry point.
Assertion helpers
Use assert_matches to assert that a value satisfies a predicate:
from predicate import ge_p
from pytest_predicate import assert_matches
def test_minimum_value():
assert_matches(10, ge_p(5))
When the assertion fails, the helper raises an AssertionError with an explanation from the predicate.
Use assert_not_matches to assert that a value does not satisfy a predicate:
from predicate import ge_p
from pytest_predicate import assert_not_matches
def test_value_below_minimum():
assert_not_matches(3, ge_p(5))
Predicate examples fixture
The predicate_examples fixture provides matching and non-matching values generated by py-predicate.
from predicate import ge_p, le_p
from pytest_predicate import assert_matches, assert_not_matches
def test_integer_range(predicate_examples):
predicate = ge_p(10) & le_p(20)
matching = predicate_examples.matching(predicate, count=10)
non_matching = predicate_examples.non_matching(predicate, count=10)
assert len(matching) == 10
assert len(non_matching) == 10
for value in matching:
assert_matches(value, predicate)
for value in non_matching:
assert_not_matches(value, predicate)
The fixture exposes two methods:
| Method | Description |
|---|---|
matching(predicate, count=10) |
Generates values that satisfy the predicate. |
non_matching(predicate, count=10) |
Generates values that do not satisfy the predicate. |
Both methods return lists containing up to count generated examples. A negative count raises ValueError.
Requirements
- Python 3.12 or later
- pytest 8 or later
- py-predicate
Development
Clone the repository and install it in editable mode:
git clone https://github.com/mrijk/pytest-predicate.git
cd pytest-predicate
pip install -e .
Run the test suite:
pytest
License
MIT
Metadata
Release files for pytest-predicate 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_predicate-0.1.0.tar.gz | 4.2 kB | Without provenance | Details for pytest_predicate-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_predicate-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_predicate-0.1.0-py3-none-any.whl |
Total release size: 9.0 kB
Release files / pytest_predicate-0.1.0.tar.gz
| Download URL | pytest_predicate-0.1.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
545a38d643066f89ec8725da5033fd7dbf0f121baad0311cf36ef2c7d5133114
|
|
BLAKE2b-256 checksum How to use checksums |
684e36e8f663d3e05edc5a619576bf53434bf589267795ea5d365fce40f82c02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.6
|
Release files / pytest_predicate-0.1.0-py3-none-any.whl
| Download URL | pytest_predicate-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b56da798fe35a261f9d366334a196d98e465118e1742af56cb3aa95c6d89fd6b
|
|
BLAKE2b-256 checksum How to use checksums |
988554ede747662b4b1eb16e61b9f69a4d7c62a1cfaf5d1657ca417f210642ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.6
|
Security for pytest-predicate 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.