Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/nedcodes-ok/cursorrules-collection/pytestgit clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collectionWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/pytest)<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/pytest"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/pytest.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00529 | $0.00529 |
| Opus 5 | $0.00264 | $0.00264 |
| Sonnet 5 | $0.00106 | $0.00106 |
| Haiku 4.5 | $0.00053 | $0.00053 |
Grade A, and why
pytest scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
Copies of this mod
1 near-identical copy found in the catalogue:
- pytest — 100% identical, 0 lines differ
How it starts
The opening of the file, as written. The whole thing — 47 lines — stays where its author put it; the contents beside it link to each section on GitHub.
pytest Cursor Rules
You are an expert in pytest testing. Follow these rules:
Structure
- Name test files test_*.py or test.py. Name test functions test
- Group related tests in classes (class TestUserAuth:) — no init needed
- Use descriptive names: test_login_fails_with_expired_token over test_login_3
- One assertion concept per test — multiple asserts are fine if testing one behavior
Fixtures
- Define fixtures in conftest.py for shared setup — pytest discovers them automatically
- Use @pytest.fixture with appropriate scope: function (default), class, module, session
- Yield fixtures for setup/teardown: yield resource then cleanup after
- Use factory fixtures (fixture that returns a factory function) for parameterized setup
- Request fixtures by name in test parameters — no imports needed
Parametrize
- Use @pytest.mark.parametrize("input,expected", [...]) for data-driven tests
- Use ids parameter for readable test names: ids=["empty", "single", "overflow"]
- Stack multiple parametrize decorators for combinatorial testing
- Use pytest.param(..., marks=pytest.mark.xfail) for expected failures in param sets
Markers
- Use @pytest.mark.slow, @pytest.mark.integration — register in pytest.ini/pyproject.toml
- Run subsets with -m "not slow" or -m integration
- Use @pytest.mark.skipif(condition, reason="...") over bare skip
- Use @pytest.mark.usefixtures("db") when you need the fixture but not its value
Assertions & Patterns
- Use plain assert — pytest rewrites them for detailed failure output
- Use pytest.raises(ExceptionType, match="pattern") as context manager
- Use pytest.approx() for float comparisons: assert result == pytest.approx(3.14, abs=1e-2)
- Use tmp_path fixture for temp files, monkeypatch for env vars and attributes
Configuration
- Configure in pyproject.toml [tool.pytest.ini_options] — not pytest.ini or setup.cfg
- Set testpaths, markers, addopts (e.g., -ra --strict-markers)
- Use --strict-markers to catch typos in marker names
- Use conftest.py at project root for shared fixtures, in subdirs for scoped ones
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- yesterday First seen · 47 lines · 529 tokens per session scan A b4e15391035b
pytest is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 529 tokens to every session, about $0.0026 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other cursor rules, from other repositories
07-testing
Cursor rule "07-testing" from orbitalsonic/AndroidPilot, covering testing, architecture, prefer, unit testing and scope.
python
Python best practices.
pytest
You are an expert in pytest testing. Follow these rules.
80-testing-quality
Testing and code quality rules.
cursorrules
You are building an AI/ML project with Python. The project uses PyTorch for model training, handles data pipelines with proper validation, tracks experiments systematically, and follows production ML engineering practices. Code is type-hinted, tested, and reproducible.
testing-pyramid-agent
Provides guidance on testing pyramid principles and how to analyze test distribution. Use this rule when discussing test distribution, test strategy, or when analyzing test coverage across unit, integration, and E2E tests.