pytest-cases
Separate test code from test cases in pytest.
What it is and what it does
pytest-cases is a pytest plugin that decouples test case definitions from test execution logic. Instead of embedding all test data inline or using pytest's built-in parametrize, you define cases separately (via decorators, fixtures, or data files) and reference them in test functions. The plugin handles the plumbing to inject each case into your test, reducing boilerplate and making test suites easier to maintain when you have many cases or shared test data.
It depends on pytest as its core framework, plus decopatch and makefun for decorator manipulation, and packaging for version handling. The package is actively maintained and classified as Production/Stable, with support for Python 3.9 through 3.14.
Use it for:
- Organize large test suites where many test functions share the same logic but differ only in input data.
- Load test cases from external files or databases without hardcoding them into test functions.
- Reuse the same test case set across multiple test functions without duplication.
- Implement lazy-loaded test cases that are only instantiated when the test runs.
- Combine multiple case sources (fixtures, decorators, data files) in a single parametrized test.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
pytest-cases lets you separate test case data from test code in pytest, using decorators and fixtures to parametrize tests with external data sources.
Yes. pytest-cases is actively maintained, has no known vulnerabilities, and solves a real problem in test organization. The low install friction and permissive license make it a straightforward addition to any pytest-based project. Install it if you have test suites with many cases or external test data that you want to keep separate from your test logic.
Install
pytest-cases on PyPI
pip
pip install pytest-casesuv
uv add pytest-casespoetry
poetry add pytest-casesInstalling pytest-cases
Before you install
Low install friction with a pure-Python wheel distribution. Actively maintained as of March 2026 with recent commits. Depends on pytest and three utility packages (decopatch, makefun, packaging), all common in Python testing environments.
License in practice
BSD 3-Clause is permissive; you can use this package in commercial and proprietary projects with minimal restriction, provided you include the license text.
Quickstart
pip install pytest-cases
from pytest_cases import CaseData, parametrize_with_cases
@parametrize_with_cases
def test_example(case_data):
assert case_data is not None
Verify before relying
- Whether the package supports Python versions earlier than 3.9 (classifiers list 3.9 as minimum but requires_python is unspecified)
- How test case data is typically sourced (files, functions, external datasets) beyond the decorator API
Package facts
| License | BSD 3-Clause (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — decopatch, makefun, packaging, pytest |
| Maintenance | actively maintained — 165 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,020,857/month — #4,491 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_cases-3.10.1-py2.py3-none-any.whl
Keywords: pytest, test, case, testcase, test-case, decorator, parametrize, parameter, data, dataset, file, separate, concerns, lazy, fixture, union
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
parametrizeProvides a `@parametrize` decorator that works…
permissive · top 15,000 on PyPI
pytest-harvestpytest-harvest captures and stores data…
permissive · top 15,000 on PyPI
pytest-parametrizationProvides decorator-based parametrization for…
permissive · top 15,000 on PyPI
pytest-lazy-fixturesAllows you to reference pytest fixtures…
permissive · top 5,000 on PyPI
pytest-lazy-fixtureAllows you to use pytest fixtures directly as…
permissive · top 15,000 on PyPI
unittest-parametrizeAdds parametrization support to unittest…
permissive · top 15,000 on PyPI
pytest-describeA pytest plugin that organizes tests into…
permissive · top 5,000 on PyPI
parameterizedParameterized testing decorator that works with…
permissive · top 5,000 on PyPI
pytest-printAdds fixtures to pytest that print messages…
permissive · top 15,000 on PyPI
pytest-datafilesA pytest plugin that copies specified files and…
permissive · top 15,000 on PyPI