Create Pytest Fixtures and Parametrized Tests for Thorough Code Coverage

Generate a full Pytest suite with reusable fixtures, parametrized edge-case tests, custom markers, and high branch coverage targets.

๐Ÿ“ The Prompt

Write a comprehensive Pytest test suite for a [PYTHON_MODULE_NAME] module that contains the following functions/classes: [FUNCTION_OR_CLASS_LIST]. The module's primary responsibility is [MODULE_PURPOSE]. Structure the test suite as follows: 1. **Fixtures** (place in `conftest.py`): - Create a `[PRIMARY_FIXTURE_NAME]` fixture that sets up [SETUP_DESCRIPTION] with scope=[SCOPE] (function/class/module/session) - Create a database/mock fixture using [MOCK_LIBRARY] (e.g., unittest.mock, pytest-mock, factory_boy) to simulate [DEPENDENCY_NAME] - Add a teardown/cleanup step that [TEARDOWN_ACTION] - Create a fixture that yields a temporary [RESOURCE_TYPE] for integration-style tests 2. **Parametrized Tests**: - Use `@pytest.mark.parametrize` to test [FUNCTION_NAME] with at least 6 input variations covering: a. Happy path with typical input b. Edge cases (empty strings, zero values, None, boundary values) c. Invalid input types that should raise [EXCEPTION_TYPE] d. Large/stress input of [LARGE_INPUT_DESCRIPTION] - Use indirect parametrize for fixture-based parameterization where appropriate 3. **Assertions & Markers**: - Use `pytest.raises` for exception testing - Add custom markers: `@pytest.mark.slow` for tests exceeding [THRESHOLD]ms - Group tests into classes by feature area 4. **Coverage Target**: Aim for [COVERAGE_PERCENT]% branch coverage. Include clear docstrings for each test explaining the scenario being validated. Output the full `conftest.py` and `test_[MODULE_NAME].py` files.

๐Ÿ’ก Tips for Better Results

List your actual function signatures and expected return types so the AI can generate realistic assertions. Specify the exact exceptions your code raises to get accurate pytest.raises blocks. Mention any async functions so the AI includes pytest-asyncio setup.

๐ŸŽฏ Use Cases

Python developers use this when they need to rapidly scaffold a thorough test suite for existing modules, especially before refactoring or when onboarding a legacy codebase to CI.

๐Ÿ”— Related Prompts

๐Ÿ’ป Coding beginner

Explain Code Like Im a Beginner

Get any code explained in plain English with line-by-line breakdowns, analogies, and learning suggestions.

๐Ÿ’ป Coding beginner

Debug My Code and Explain the Fix

Get your code debugged with clear explanations of what went wrong and why, plus the corrected version.

๐Ÿ’ป Coding intermediate

Write Unit Tests for My Code

Generate thorough unit tests covering edge cases, error handling, and both positive and negative scenarios.

๐Ÿ’ป Coding intermediate

Convert Code Between Languages

Convert code between any programming languages while maintaining idiomatic patterns and best practices.

๐Ÿ’ป Coding intermediate

Write a REST API Endpoint

Generate production-ready REST API endpoints with validation, error handling, and documentation.

๐Ÿ’ป Coding advanced

Create a GitHub Actions CI/CD Workflow for Automated Testing and Deployment

Generate a complete GitHub Actions CI/CD workflow with build, test, deploy, and notification jobs for your project.