skillfed

pytest-cases

Separate test code from test cases in pytest.

pytest-cases v3.10.1 1.0M downloads/30d#4,491 on PyPI376
Permissive license BSD 3-Clause Active released

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-cases

uv

uv add pytest-cases

poetry

poetry add pytest-cases

Installing 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

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: Testing

Tags

pytest parametrize test casesseparate test data from codepytest test case decoratorparametrized testing pytestpytest fixture data managementlazy test case loadingpytest case-driven testing
pytest-plugintest-parametrizationdata-driven-testing

More Python Modules packages