{"library":"pytest-cases","title":"pytest-cases","description":"pytest-cases is a Python library that extends pytest to enable the separation of test code from test cases, allowing for more modular and reusable tests. It leverages pytest's parametrization capabilities to define test data and expected results in 'case functions,' which are then injected into test functions. The library is actively maintained, with frequent minor and patch releases to ensure compatibility with new pytest and Python versions, as well as to introduce new features.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install pytest-cases"],"cli":null},"imports":["from pytest_cases import parametrize_with_cases","from pytest_cases import case","from pytest_cases import fixture","from pytest_cases import current_cases"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pytest\nfrom pytest_cases import parametrize_with_cases, case\n\n# test_foo_cases.py\n@case\ndef case_positive_int():\n    return 10\n\n@case\ndef case_another_positive_int():\n    return 20\n\n# test_foo.py\ndef foo(a):\n    return a + 5\n\n@parametrize_with_cases(\"a\", cases=\".test_foo_cases\")\ndef test_foo_function(a):\n    \"\"\"Tests the foo function with various cases.\"\"\"\n    expected_result = a + 5\n    assert foo(a) == expected_result\n\n# To run these tests:\n# 1. Save the case functions in a file named `test_foo_cases.py`.\n# 2. Save the test function in a file named `test_foo.py`.\n# 3. Run `pytest` in the directory containing these files.\n# Expected output will show tests passing for both case_positive_int and case_another_positive_int.","lang":"python","description":"This quickstart demonstrates how to define test cases in a separate file using the `@case` decorator and then use `parametrize_with_cases` to inject these cases into a test function. The `cases` argument points to the module containing the case functions. When `pytest` is run, it will automatically discover and execute `test_foo_function` twice, once for each defined case, allowing for clear separation of test logic and test data.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"3.10.1","pypi_latest":"3.10.1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.9,"avg_import_s":0.49,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.5,"mem_mb":12.3,"disk_size":"31.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.9,"import_time_s":0.35,"mem_mb":12.3,"disk_size":"32M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.63,"mem_mb":13.2,"disk_size":"34.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.8,"import_time_s":0.55,"mem_mb":13.2,"disk_size":"35M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.56,"mem_mb":13,"disk_size":"26.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.7,"import_time_s":0.55,"mem_mb":13,"disk_size":"27M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.51,"mem_mb":12.6,"disk_size":"26.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.7,"import_time_s":0.48,"mem_mb":12.6,"disk_size":"27M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.43,"mem_mb":11.6,"disk_size":"31.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pytest-cases","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.3,"import_time_s":0.37,"mem_mb":11.6,"disk_size":"31M"}]}}