pytest
Skill15 starsChanged 2 months agoMITView on GitHub
Expert Pytest testing assistance covering fixtures, parametrization, marks, and test plugins. Use when writing Python tests, building test suites, or running `pytest` in CI/CD pipelines.
8 other projects use a version of this.
Adopted by
Most recently taken up by
- amutaal122/ai-engineer-mastertheir own version, first seen Nov 29, 2026
- marcioaltoe/skillstheir own version, first seen Nov 29, 2026
- UlisesCm/navori-owltheir own version, first seen Nov 22, 2026
- Taimoor-Kamran/claude-code-skillstheir own version, first seen Nov 22, 2026
- nealepetrillo/claude-skills-pytesttheir own version, first seen Nov 22, 2026
- prowler-cloud/prowlertheir own version, first seen Oct 8, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- prowler-cloud/prowler★ 15ksame name
- microsoft/debugpy★ 2.5ksame name
- imankulov/skills★ 4same name
- nealepetrillo/claude-skills-pytest★ 1same name
- Taimoor-Kamran/claude-code-skills★ 1same name
- UlisesCm/navori-owl★ 1same name
- amutaal122/ai-engineer-master★ 0same name
- marcioaltoe/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 1 is distinctive, and 5 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 100
Use @pytest.fixture with the yield statement:
- Very specific: line 123
Use Plain assert Statements: Pytest provides detailed assertion introspection without requiring special assertion methods.
- Very specific: line 124
Use conftest.py for Shared Fixtures: Place global fixtures and configuration hooks in conftest.py files.
- Very specific: line 125
Run Parallel Tests with pytest-xdist: Accelerate test runs across all CPU cores with pytest -n auto.
- Very specific: line 130
Use assert with parentheses: Writing assert(a == b, "msg") evaluates a non-empty tuple which is always truthy.
- Distinctive: line 132
Create deep nested class hierarchies: Pytest favors simple standalone test functions over unittest-style classes.
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pytest
Pytest is the dominant testing framework for Python. It is loved for its no-boilerplate syntax (assert x == y), powerful fixture system, and rich plugin ecosystem.
When to Use
- Python Standard Testing Framework: The most widely adopted, powerful testing framework for Python web backends, data science, and ML.
- Clean Fixture Dependency Injection: Managing test setup, database connections, and teardown cleanly with
@pytest.fixture. - Parameterized Testing: Running test functions across multi-dimensional input sets with
@pytest.mark.parametrize. - Rich Plugin Ecosystem: Extending capabilities via
pytest-asyncio,pytest-cov,pytest-xdist, andpytest-mock.
Quick Start
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5Running it:
pytestCore Concepts
Dependency Injection with Fixtures
Fixtures provide modular, reusable dependencies with explicit lifecycle scopes:
# conftest.py
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
@pytest.fixture(scope="session")
def db_engine():
engine = create_engine("sqlite:///:memory:")
yield engine
engine.dispose()
@pytest.fixture
def db_session(db_engine):
Session = sessionmaker(bind=db_engine)
session = Session()
yield session
session.rollback()
session.close()Parameterized Tests (@pytest.mark.parametrize)
Tests multiple input/output scenarios cleanly without loop boilerplate:
import pytest
@pytest.mark.parametrize("email,expected_valid", [
("user@example.com", True),
("invalid-email", False),
("@missinguser.com", False),
("user.name+tag@sub.domain.co", True),
])
def test_email_validation(email, expected_valid):
assert validate_email(email) == expected_validAsync Testing with pytest-asyncio
Tests async coroutines seamlessly:
import pytest
import httpx
@pytest.mark.asyncio
async def test_async_fetch():
async with httpx.AsyncClient() as client:
response = await client.get("https://httpbin.org/get")
assert response.status_code == 200Common Patterns
Scoped Fixtures with Teardown / Cleanup
Problem: Database or mock setup code repeated across dozens of test functions creates duplication and leftover state.
Solution:
Use @pytest.fixture with the yield statement:
import pytest
@pytest.fixture(scope="function")
def db_session():
# Setup test database session
session = create_test_session()
yield session
# Cleanup and rollback after test completes
session.rollback()
session.close()
def test_user_creation(db_session):
user = db_session.create_user("alice@example.com")
assert user.id is not NoneBest Practices
Do:
- Use Plain
assertStatements: Pytest provides detailed assertion introspection without requiring special assertion methods. - Use
conftest.pyfor Shared Fixtures: Place global fixtures and configuration hooks inconftest.pyfiles. - Run Parallel Tests with
pytest-xdist: Accelerate test runs across all CPU cores withpytest -n auto. - Mark Tests by Category: Use custom marks (
@pytest.mark.slow,@pytest.mark.integration) and filter runs with-m "not slow".
Don't:
- Use
assertwith parentheses: Writingassert(a == b, "msg")evaluates a non-empty tuple which is always truthy. - Mutate shared session-scoped fixtures: Keep session fixtures read-only; use function-scoped fixtures for test-isolated mutations.
- Create deep nested class hierarchies: Pytest favors simple standalone test functions over unittest-style classes.
Troubleshooting
| Error | Cause | Solution |
ModuleNotFoundError: No module named 'src' | Current directory not in sys.path when running pytest. | Run pytest as a module: python -m pytest, or configure pythonpath = ["src"] in pyproject.toml. |
FixtureNotFound: fixture '...' not found | Typo in fixture argument name or fixture defined outside conftest.py. | Move shared fixtures to root conftest.py file. |
Failed: DID NOT RAISE <class '...'> | Code did not raise the exception expected by pytest.raises. | Inspect inputs to verify failure condition is actually triggered. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

