← ClaudeAtlas

pytest-masterylisted

Python testing with pytest using uv package manager. Use when: (1) Running Python tests, (2) Writing test files or test functions, (3) Setting up fixtures, (4) Parametrizing tests, (5) Generating coverage reports, (6) Testing FastAPI applications, (7) Debugging test failures, (8) Configuring pytest options. Triggers: "run tests", "write tests", "test coverage", "pytest", "unit test", "integration test", "test FastAPI".
aiskillstore/marketplace · ★ 329 · Testing & QA · score 79
Install: claude install-skill aiskillstore/marketplace
# pytest Testing with uv ## Quick Reference ```bash # Run all tests uv run pytest # Run with verbose output uv run pytest -v # Run specific file uv run pytest tests/test_example.py # Run specific test function uv run pytest tests/test_example.py::test_function_name # Run tests matching pattern uv run pytest -k "pattern" # Run with coverage uv run pytest --cov=src --cov-report=html ``` ## Installation ```bash # Add pytest as dev dependency uv add --dev pytest # Add coverage support uv add --dev pytest-cov # Add async support (for FastAPI) uv add --dev pytest-asyncio httpx ``` ## Test Discovery pytest automatically discovers tests following these conventions: - Files: `test_*.py` or `*_test.py` - Functions: `test_*` - Classes: `Test*` (no `__init__` method) - Methods: `test_*` inside `Test*` classes Standard project structure: ``` project/ ├── src/ │ └── myapp/ ├── tests/ │ ├── __init__.py │ ├── conftest.py # Shared fixtures │ ├── test_unit.py │ └── integration/ │ └── test_api.py └── pyproject.toml ``` ## Fixtures Fixtures provide reusable test setup/teardown: ```python import pytest @pytest.fixture def sample_user(): return {"id": 1, "name": "Test User"} @pytest.fixture def db_connection(): conn = create_connection() yield conn # Test runs here conn.close() # Teardown def test_user_name(sample_user): assert sample_user["name"] == "Test User" ``` ### Fixture Scopes ```python @pytest.fixture(scope="function") # D