Provides Python testing patterns using pytest, fixtures, mocking, parameterization, and property-based testing. Use when writing unit tests, integration tests, or implementing TDD.
Ships in nickcrew-claude-ctx-plugin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and property-based testing.
Test Discovery: Files matching test_*.py or *_test.py, functions starting with test_
Fixtures: Reusable test resources with setup and teardown
function (default), class, module, sessionconftest.py for project-wide availabilityAssertions: Use assert statements, pytest.raises() for exceptions
Organization: Separate unit/, integration/, e2e/ directories
Load detailed references for specific topics:
| Task | Reference File |
|---|---|
| Pytest basics, test structure, AAA pattern | skills/python-testing-patterns/references/pytest-fundamentals.md |
| Fixtures, scopes, setup/teardown, conftest.py | skills/python-testing-patterns/references/fixtures.md |
| Parametrization, multiple test cases | skills/python-testing-patterns/references/parametrized-tests.md |
| Mocking, patching, unittest.mock, pytest-mock | skills/python-testing-patterns/references/mocking.md |
| Async tests, pytest-asyncio, event loops | skills/python-testing-patterns/references/async-testing.md |
| Property-based testing, Hypothesis, strategies | skills/python-testing-patterns/references/property-based-testing.md |
| Monkeypatch, environment variables, attributes | skills/python-testing-patterns/references/monkeypatch.md |
| Test structure, markers, conftest.py patterns | skills/python-testing-patterns/references/test-organization.md |
| Coverage measurement, reports, thresholds | skills/python-testing-patterns/references/coverage.md |
| Database, API, Redis, message queue testing | skills/python-testing-patterns/references/integration-testing.md |
| Best practices, test quality, fixture design | skills/python-testing-patterns/references/best-practices.md |
# test_example.py
import pytest
def test_something():
"""Descriptive test name."""
# Arrange
expected = 5
# Act
result = 2 + 3
# Assert
assert result == expected
Run tests:
pytest # Run all tests
pytest -v # Verbose output
pytest tests/unit/ # Specific directory
pytest -k "test_user" # Match pattern
pytest -m unit # Run marked tests
@pytest.fixture
def sample_data():
"""Provide test data."""
data = {"key": "value"}
yield data
# Cleanup if needed
def test_with_fixture(sample_data):
assert sample_data["key"] == "value"
@pytest.mark.parametrize("input,expected", [
(2, 4),
(3, 9),
(4, 16),
])
def test_square(input, expected):
assert input ** 2 == expected
from unittest.mock import patch
@patch("module.external_api_call")
def test_with_mock(mock_api):
mock_api.return_value = {"status": "ok"}
result = my_function()
assert result["status"] == "ok"
mock_api.assert_called_once()
pytest --cov=src --cov-report=term-missing
pytest --cov=src --cov-report=html
pytest --cov=src --cov-fail-under=80
pytest.ini:
[pytest]
testpaths = tests
python_files = test_*.py
addopts = -v --strict-markers --cov=src
markers =
unit: Unit tests
integration: Integration tests
slow: Slow tests
Exception testing:
with pytest.raises(ValueError, match="error message"):
function_that_raises()
Async testing:
@pytest.mark.asyncio
async def test_async_function():
result = await async_operation()
assert result is not None
Temporary files:
def test_file_operation(tmp_path):
test_file = tmp_path / "test.txt"
test_file.write_text("content")
assert test_file.read_text() == "content"
Markers for test selection:
@pytest.mark.slow
@pytest.mark.integration
def test_database_operation():
pass
Not using fixtures: Repeating setup code across tests
Tests depending on order: Global state pollution
Over-mocking: Mocking internal implementation
Missing edge cases: Only testing happy path
Slow tests: Running full integration tests frequently
Ignoring coverage gaps: Not measuring test coverage
Poor test names: Generic names like test_1()
test_<behavior>_<condition>_<expected>No cleanup: Resources not released
references/async-testing.md (opens in a new tab)references/best-practices.md (opens in a new tab)references/coverage.md (opens in a new tab)references/fixtures.md (opens in a new tab)references/integration-testing.md (opens in a new tab)references/mocking.md (opens in a new tab)references/monkeypatch.md (opens in a new tab)references/parametrized-tests.md (opens in a new tab)references/property-based-testing.md (opens in a new tab)references/pytest-fundamentals.md (opens in a new tab)references/test-organization.md (opens in a new tab)validation/rubric.yaml (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
156 skills in this plugin
/accessibility-auditFast, high-signal accessibility triage for pages, components, or PRs targeting WCAG 2.2 AA compliance./agent-loopsComplete operational workflow for implementer agents (Codex, Gemini, etc.) making code changes and writing tests. Drives all work through atomic commits — each loop operates on the smallest complete, reviewable change. Defines the Code Change Loop, Test Writing Loop, Lint Gate, and Issue Filing process with circuit breakers, severity levels, and escalation rules. Requires `cortex git commit` for all commits. Includes bundled provider-aware review scripts that keep same-model shell-outs as the last resort, plus a fresh-context Codex fallback for code review and test audit. Use this skill when starting any implementation task./ai-tells-reviewUse when public prose still sounds machine-written after ai-tells-scan. Complements ai-tells-scan's mechanical pass with structural judgment: rhythm, hedging, rhetorical reflexes, and performative emphasis. Trigger on 'review for AI tells,' 'does this read AI,' 'strip the AI smell,' or 'make this less AI.'/ai-tells-scanUse when writing tasks produce prose artifacts (READMEs, docs, PR text, tutorials, guides, posts, release notes) and need a fast surface scan for AI tells. Auto-engages on prose writing tasks; checks banned punctuation, stock vocabulary, and mechanical patterns. For the structural judgment pass on rhythm and rhetorical reflexes, use ai-tells-review. Not a replacement for voice skills like nick-voice; this removes machine fingerprints, it does not add a target voice./api-design-patternsComprehensive REST and GraphQL API design patterns with versioning, pagination, error handling, and HATEOAS principles. Use when designing APIs, defining endpoints, or architecting service contracts requiring production-grade patterns./api-gateway-patternsAPI Gateway patterns for routing, authentication, rate limiting, and service composition in microservices architectures. Use when implementing API gateways, building BFF layers, or managing service-to-service communication at scale./nickcrew-claude-ctx-plugin:python-testing-patternsfrom nickcrew-claude-ctx-plugin
nickcrew-claude-ctx-plugin@cascade-code-languages-misc-1 is listed by joshuarweaver/cascade-code-languages-misc-1 — review the source before installing
npx claudepluginhub joshuarweaver/cascade-code-languages-misc-1 --plugin nickcrew-claude-ctx-pluginOther plugins' skills for the same job