Advanced pytest parametrization plugin that generates test case instances from sync or async factories.
Project description
pytest-case-provider
Case parametrization for pytest with fixture, class, and async support.
Provides declarative, typed case injection for both sync and async test functions.
Overview
pytest-case-provider extends pytest’s parametrization system.
It was inspired by pytest-cases, but redesigned from scratch for strict typing, async support, and fixture-native case injection.
It allows attaching case providers directly to test functions or methods via @inject_cases and
@inject_cases_method.
Cases can be:
- Synchronous or asynchronous.
- Iterable or async-iterable.
- Fixture-dependent.
- Composable across tests or classes.
API Summary
| Symbol | Description |
|---|---|
inject_cases |
Decorator/injector for test functions |
inject_cases_method |
Same as above, for test class methods |
CaseStorage[T] |
Mutable case storage container |
CompositeCaseStorage[T] |
Aggregates multiple CaseCollector |
Installation
pip install pytest-case-provider
Usage example
import typing
from dataclasses import dataclass, replace
import pytest
from pytest_case_provider import inject_cases, inject_cases_method
@dataclass(frozen=True)
class MyCase:
foo: int
@pytest.fixture
def number() -> int:
return 42
# Regular test
def test_without_case_injection() -> None:
assert True
# Case-enabled test function
@inject_cases
def test_case_injected(case: MyCase) -> None:
assert isinstance(case, MyCase)
# Cross-inject from another test
@inject_cases(test_case_injected)
def test_case_increment(case: MyCase, case_foo_inc: MyCase) -> None:
assert case.foo + 1 == case_foo_inc.foo
# Define case providers
@test_case_injected.case()
def case_one() -> MyCase:
return MyCase(foo=1)
@test_case_injected.case()
def case_two() -> MyCase:
return MyCase(foo=2)
# Use other fixtures in case providers
@test_case_injected.case()
def case_number(number: int) -> MyCase:
return MyCase(foo=number)
# Async case provider
@test_case_injected.case()
async def case_async_generated() -> MyCase:
return MyCase(foo=999)
# Iterable provider
@test_case_injected.case()
def case_iterable() -> typing.Iterator[MyCase]:
yield MyCase(foo=10)
# Async iterable provider
@test_case_injected.case()
async def case_async_iterable() -> typing.Iterator[MyCase]:
yield MyCase(foo=20)
# Access case object from fixture
@pytest.fixture
def case_foo_inc(case: MyCase) -> MyCase:
return replace(case, foo=case.foo + 1)
# Example class-based usage
class TestClass:
@inject_cases_method
def test_class_cases(self, case: MyCase) -> None:
assert isinstance(case, MyCase)
@test_class_cases.case()
def case_three(self) -> MyCase:
return MyCase(foo=3)
@test_class_cases.case()
def case_four(self) -> MyCase:
return MyCase(foo=4)
Test Discovery Output
Pytest will expand each injected case as a distinct test variant using pytest's parametrization:
test_example.py::test_case_injected[case_one]
test_example.py::test_case_injected[case_two]
test_example.py::test_case_injected[case_number]
test_example.py::test_case_injected[case_async_generated]
test_example.py::test_case_injected[case_iterable]
test_example.py::test_case_injected[case_async_iterable]
test_example.py::test_case_increment[case_one]
test_example.py::test_case_increment[case_two]
test_example.py::test_case_increment[case_number]
test_example.py::test_case_increment[case_async_generated]
test_example.py::test_case_increment[case_iterable]
test_example.py::test_case_increment[case_async_iterable]
test_example.py::TestClass::test_class_cases[case_three]
test_example.py::TestClass::test_class_cases[case_four]
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.2.0.tar.gz.
File metadata
- Download URL: pytest_case_provider-0.2.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
293731fb2d1723261fb1a0cce087d8fa9febd384965708fd64a4c4f53f89d91b
|
|
| MD5 |
cc2ab8a85cfc2d6293b97599448bd286
|
|
| BLAKE2b-256 |
2e1973dc4c04b09b697c3825e7f1531b61839e3795a71c86b00c80f6876c18f7
|
Provenance
The following attestation bundles were made for pytest_case_provider-0.2.0.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.2.0.tar.gz -
Subject digest:
293731fb2d1723261fb1a0cce087d8fa9febd384965708fd64a4c4f53f89d91b - Sigstore transparency entry: 642057834
- Sigstore integration time:
-
Permalink:
zerlok/pytest-case-provider@d73ff4897525cbecfb93a2a6501a5cc10da57de0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@d73ff4897525cbecfb93a2a6501a5cc10da57de0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_case_provider-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pytest_case_provider-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.1 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 |
06e6762ef1cb3d3c3cef7278263248d30afb35b6cf80daedd6622820dac8d85d
|
|
| MD5 |
0207aeb5ddd4f9f2b84129fdaffef058
|
|
| BLAKE2b-256 |
fcb5af2011e0589f30709f9f5c1fbcbab464b993ca4593618bddc6018b26ca98
|
Provenance
The following attestation bundles were made for pytest_case_provider-0.2.0-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.2.0-py3-none-any.whl -
Subject digest:
06e6762ef1cb3d3c3cef7278263248d30afb35b6cf80daedd6622820dac8d85d - Sigstore transparency entry: 642057836
- Sigstore integration time:
-
Permalink:
zerlok/pytest-case-provider@d73ff4897525cbecfb93a2a6501a5cc10da57de0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@d73ff4897525cbecfb93a2a6501a5cc10da57de0 -
Trigger Event:
release
-
Statement type: