Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aiskillstore avatar

Pytest Mastery

  • 1 installs
  • 404 repo stars
  • Updated August 5, 2026
  • aiskillstore/marketplace

pytest-mastery is a Claude Code skill for Python testing with pytest using the uv package manager, covering fixtures, parametrization, coverage, and FastAPI testing.

About

pytest-mastery is a Claude Code skill for Python testing with pytest using the uv package manager. It covers test discovery conventions, fixtures and scopes, parametrization, markers, coverage reports, pyproject.toml configuration, and FastAPI testing. A developer uses it to run tests, write test files and fixtures, generate coverage, and debug failing tests.

  • Python testing with pytest run through the uv package manager
  • Covers fixtures, parametrization, markers, and coverage reports
  • Includes FastAPI testing patterns and a bundled run_tests.py script

Pytest Mastery by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #1,750 of 2,153 Testing & QA skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
At a glance

pytest-mastery capabilities & compatibility

Free; a testing-pattern skill with no external service

Capabilities
testing · code coverage · api testing
Use cases
testing · api development
Pricing
Free
From the docs

What pytest-mastery says it does

Python testing with pytest using uv package manager.
SKILL.md
pytest automatically discovers tests following these conventions:
SKILL.md
npx skills add https://github.com/aiskillstore/marketplace --skill pytest-mastery

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars404
Last updatedAugust 5, 2026
Repositoryaiskillstore/marketplace

What it does

Write and run Python pytest suites with fixtures, parametrization, coverage, and FastAPI testing.

Who is it for?

Writing, running, and configuring pytest suites for Python and FastAPI projects

Skip if: Non-Python testing or test frameworks other than pytest

When should I use this skill?

Running Python tests, writing test files, setting up fixtures, generating coverage, or testing FastAPI

What you get

Well-structured pytest suites with fixtures, coverage thresholds, and FastAPI test patterns.

  • pytest test files and fixtures
  • coverage reports
  • pyproject.toml test config

By the numbers

  • lists 12 common pytest CLI options
  • coverage example uses --cov-fail-under=80

Files

SKILL.mdMarkdownGitHub ↗

pytest Testing with uv

Quick Reference

# 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

# 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:

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

@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

Shared Fixtures (conftest.py)

Place in tests/conftest.py for automatic availability:

# tests/conftest.py
import pytest

@pytest.fixture
def api_client():
    return TestClient(app)

Parametrization

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

Common Options

OptionDescription
-vVerbose output
-vvMore verbose
-qQuiet mode
-xStop on first failure
--lfRun last failed tests only
--ffRun failures first
-k "expr"Filter by name expression
-m "mark"Run marked tests only
--tb=shortShorter traceback
--tb=noNo traceback
-sShow print statements
--durations=10Show 10 slowest tests
-n autoParallel execution (pytest-xdist)

Coverage Reports

# 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

Markers

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"

pyproject.toml Configuration

[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:",
]

FastAPI Testing

See references/fastapi-testing.md for comprehensive FastAPI testing patterns including:

  • TestClient setup
  • Async testing with httpx
  • Database fixture patterns
  • Dependency overrides
  • Authentication testing

Debugging Failed Tests

# 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

Related skills

FAQ

What package manager does pytest-mastery use?

uv - tests run via 'uv run pytest' and dev dependencies are added with 'uv add --dev pytest'.

Does it cover FastAPI?

Yes - references/fastapi-testing.md covers TestClient setup, async testing with httpx, database fixtures, and dependency overrides.

Testing & QAtestingbackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.