skills/abdullahmalik17/pytest-mastery/SKILL.md
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".
npx skillsauth add aiskillstore/marketplace pytest-masteryInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
# 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
# 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
pytest automatically discovers tests following these conventions:
test_*.py or *_test.pytest_*Test* (no __init__ method)test_* inside Test* classesStandard project structure:
project/
├── src/
│ └── myapp/
├── tests/
│ ├── __init__.py
│ ├── conftest.py # Shared fixtures
│ ├── test_unit.py
│ └── integration/
│ └── test_api.py
└── pyproject.toml
Fixtures provide reusable test setup/teardown:
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"
@pytest.fixture(scope="function") # Default: new instance per test
@pytest.fixture(scope="class") # Once per test class
@pytest.fixture(scope="module") # Once per module
@pytest.fixture(scope="session") # Once per test session
Place in tests/conftest.py for automatic availability:
# tests/conftest.py
import pytest
@pytest.fixture
def api_client():
return TestClient(app)
Run same test with multiple inputs:
import pytest
@pytest.mark.parametrize("input,expected", [
(1, 2),
(2, 4),
(3, 6),
])
def test_double(input, expected):
assert input * 2 == expected
@pytest.mark.parametrize("value", [None, "", [], {}])
def test_falsy_values(value):
assert not value
| Option | Description |
|--------|-------------|
| -v | Verbose output |
| -vv | More verbose |
| -q | Quiet mode |
| -x | Stop on first failure |
| --lf | Run last failed tests only |
| --ff | Run failures first |
| -k "expr" | Filter by name expression |
| -m "mark" | Run marked tests only |
| --tb=short | Shorter traceback |
| --tb=no | No traceback |
| -s | Show print statements |
| --durations=10 | Show 10 slowest tests |
| -n auto | Parallel execution (pytest-xdist) |
# Terminal report
uv run pytest --cov=src
# HTML report (creates htmlcov/)
uv run pytest --cov=src --cov-report=html
# With minimum threshold (fails if below)
uv run pytest --cov=src --cov-fail-under=80
# Multiple report formats
uv run pytest --cov=src --cov-report=term --cov-report=xml
import pytest
@pytest.mark.slow
def test_slow_operation():
...
@pytest.mark.skip(reason="Not implemented")
def test_future_feature():
...
@pytest.mark.skipif(condition, reason="...")
def test_conditional():
...
@pytest.mark.xfail(reason="Known bug")
def test_known_failure():
...
Run by marker:
uv run pytest -m "not slow"
uv run pytest -m "integration"
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
python_functions = ["test_*"]
addopts = "-v --tb=short"
markers = [
"slow: marks tests as slow",
"integration: integration tests",
]
[tool.coverage.run]
source = ["src"]
omit = ["tests/*", "*/__init__.py"]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
]
See references/fastapi-testing.md for comprehensive FastAPI testing patterns including:
# Run with full traceback
uv run pytest --tb=long
# Drop into debugger on failure
uv run pytest --pdb
# Show local variables in traceback
uv run pytest -l
# Run only previously failed
uv run pytest --lf
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.