---
name: "pytest-fixtures-parametrization"
description: "Write comprehensive, clean Python test suites using pytest fixtures and test matrices."
metadata:
  author: "pytest-dev"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "write pytest fixture"
  - "parametrize test pytest"
  - "async test pytest-asyncio"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# pytest Fixtures, Parametrization & Mock Testing

Implements pytest: authoring fixtures with yield teardown in conftest.py, scoping (function, module, session), test matrix parametrization (@pytest.mark.parametrize), monkeypatching, and async testing with pytest-asyncio.

## When to Invoke
Invoke this skill whenever you need to:
- write pytest fixture
- parametrize test pytest
- async test pytest-asyncio

## Execution SOP & Rules
1. Define fixtures in conftest.py: @pytest.fixture(scope='function') def test_client(): yield client.
2. Parametrize tests: @pytest.mark.parametrize('input,expected', [(1, 2), (2, 4), (3, 6)]).
3. Run tests with coverage: pytest --cov=app --cov-report=term-missing.
4. Use monkeypatch.setenv('ENV', 'test') to safely isolate environment variables during test runs.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
