Advanced pytest parametrization plugin that generates test case instances from sync or async factories.
Project description
pytest-case-provider
Parametrization for pytest with fixture support, async support, class-method support, shared storage, and module-level case discovery. Declarative, typed, on-demand injection for sync, async, iterable, and async-iterable providers.
Overview
Extends pytest’s parametrization layer with case storages and containers. Containers attach case sets to test functions and test methods via inject_func and inject_method. Fixtures integrate natively. Async is supported. Matching case_*.py modules are scanned and loaded. Duplicate case names collapse to single instances.
Core Concepts
Providers
Functions that yield case values. Supported forms:
- Sync
- Async
- Iterable
- Async iterable
- Fixture-dependent
Storage
CaseStorage instances hold providers. CompositeCaseStorage merges multiple storages.
Container
CaseContainer wraps a storage and exposes:
.case().include().inject_func().inject_method()
A single container instance feeds any number of tests.
Injectors
inject_func() and inject_method() create isolated containers for direct use. .include() attaches external storages to them.
Module-Level Loading
If test_x.py exists alongside case_x.py, the plugin imports the case module and registers its providers. Tests using inject_func() or inject_method() receive matching providers. Matching is based on the type annotation of the case parameter.
Installation
pip install pytest-case-provider
Quick Start
# test_example.py
import typing
from dataclasses import dataclass
from pytest_case_provider import CaseContainer
@dataclass(frozen=True)
class MyCase:
foo: int
container = CaseContainer[MyCase]()
@container.inject_func()
def test_cases(case: MyCase) -> None:
assert isinstance(case, MyCase)
class TestGroup:
@container.inject_method()
def test_group(self, case: MyCase) -> None:
assert case.foo >= 1
@container.case()
def case_small() -> MyCase:
return MyCase(foo=1)
@container.case()
async def case_async() -> MyCase:
return MyCase(foo=999)
@container.case()
def case_range() -> typing.Iterator[MyCase]:
yield MyCase(foo=10)
Module-Level Case Files
tests/
test_math.py
case_math.py
case_math.py:
from dataclasses import dataclass
@dataclass(frozen=True)
class MathCase:
x: int
y: int
def case_x1_y2() -> MathCase:
return MathCase(1, 2)
test_math.py:
from pytest_case_provider import inject_func
from tests.case_math import MathCase
@inject_func()
def test_add(case: MathCase) -> None:
assert case.x + case.y == 3
The plugin imports case_math and binds its providers to the injector.
Pytest Expansion
test_example.py::test_cases[case_small]
test_example.py::test_cases[case_async]
test_example.py::test_cases[case_range0]
test_example.py::test_cases[case_range1]
test_example.py::TestGroup::test_group[case_small]
test_example.py::TestGroup::test_group[case_async]
test_example.py::TestGroup::test_group[case_range0]
test_example.py::TestGroup::test_group[case_range1]
Notes
- Async requires
pytest-asyncio. - AnyIO execution paths are disabled.
- Case deduplication follows provider-name semantics.
Project details
Release history Release notifications | RSS feed
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 pytest_case_provider-0.4.2.tar.gz.
File metadata
- Download URL: pytest_case_provider-0.4.2.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5be2822b51c5078162b20a63d7ade9045ee86a54f1842690256c14db89515adf
|
|
| MD5 |
ed676197976bbba6c3b7ac29c7fb468b
|
|
| BLAKE2b-256 |
8ca615488d35353bee09dd0dddb00af34cceab0aa968e9671143688c5a0bc5c3
|
Provenance
The following attestation bundles were made for pytest_case_provider-0.4.2.tar.gz:
Publisher:
publish.yaml on zerlok/pytest-case-provider
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_case_provider-0.4.2.tar.gz -
Subject digest:
5be2822b51c5078162b20a63d7ade9045ee86a54f1842690256c14db89515adf - Sigstore transparency entry: 747822715
- Sigstore integration time:
-
Permalink:
zerlok/pytest-case-provider@8bb7a019e6a7781f645deff8e186becdd660b674 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@8bb7a019e6a7781f645deff8e186becdd660b674 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_case_provider-0.4.2-py3-none-any.whl.
File metadata
- Download URL: pytest_case_provider-0.4.2-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d398935ec8b99b939e3c91cd1847e35990d1ec9260a2702e1638705cf3f8a86
|
|
| MD5 |
40026f51e221ffa2f8af7343d153e662
|
|
| BLAKE2b-256 |
14b7610aeb117430bd5aeb0f1ad3f6e0d4dfd9ec6a8d82477347b035029a9438
|
Provenance
The following attestation bundles were made for pytest_case_provider-0.4.2-py3-none-any.whl:
Publisher:
publish.yaml on zerlok/pytest-case-provider
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_case_provider-0.4.2-py3-none-any.whl -
Subject digest:
1d398935ec8b99b939e3c91cd1847e35990d1ec9260a2702e1638705cf3f8a86 - Sigstore transparency entry: 747822716
- Sigstore integration time:
-
Permalink:
zerlok/pytest-case-provider@8bb7a019e6a7781f645deff8e186becdd660b674 -
Branch / Tag:
refs/tags/v0.4.2 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@8bb7a019e6a7781f645deff8e186becdd660b674 -
Trigger Event:
release
-
Statement type: