Metadata-Version: 2.4
Name: pytest-predicate
Version: 0.1.0
Summary: Pytest integration for py-predicate
Author-email: Maurits Rijk <maurits.rijk@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/mrijk/pytest-predicate
Project-URL: Issues, https://github.com/mrijk/pytest-predicate/issues
Project-URL: Changelog, https://github.com/mrijk/pytest-predicate/blob/main/CHANGELOG.md
Keywords: pytest,pytest-plugin,predicate,py-predicate,testing,assertions
Classifier: Framework :: Pytest
Classifier: Typing :: Typed
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: py-predicate>=1.11
Requires-Dist: pytest>=8
Dynamic: license-file

# pytest-predicate

[![PyPI version](https://img.shields.io/pypi/v/pytest-predicate)](https://pypi.org/project/pytest-predicate/)
[![Python versions](https://img.shields.io/pypi/pyversions/pytest-predicate)](https://pypi.org/project/pytest-predicate/)

**pytest-predicate** provides pytest integration for [py-predicate](https://github.com/mrijk/py-predicate).

It includes assertion helpers and fixtures for testing predicates with examples that should match or not match.

## Installation

```bash
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:

```python
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:

```python
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`.

```python
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](https://github.com/mrijk/py-predicate)

## Development

Clone the repository and install it in editable mode:

```bash
git clone https://github.com/mrijk/pytest-predicate.git
cd pytest-predicate

pip install -e .
```

Run the test suite:

```bash
pytest
```

## License

MIT
