agentleFS
existential-birdsexistential-birds/beagle/skills/pytest-code-review/SKILL.md

pytest-code-review

Skill91 starsChanged 4 days agoApache-2.0View on GitHub

Reviews pytest test code for pytest-asyncio configuration, async resource cleanup, fixture scoping, parametrize usage, and mock/patch correctness. Use when reviewing test_*.py or conftest.py files.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do patch() calls target the call-site namespace, use AsyncMock/spec_set, and verify arguments accurately?

    line 59

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Pytest Code Review

Quick Reference

Issue TypeReference
pytest-asyncio strict/auto mode, AsyncMock, task cleanupreferences/async-testing.md
conftest.py, tmp_path, fixture scope, async try/finally cleanupreferences/fixtures.md
@pytest.mark.parametrize, pytest.param, indirect fixturesreferences/parametrize.md
Call-site patch(), AsyncMock, spec_set, mockerreferences/mocking.md

Review gates

Work in order. Do not assert pytest-specific problems until each applicable gate passes.

  1. Scoped files — Pass when: You list every test_*.py and any conftest.py you will cite; no findings for files outside that list.
  2. Async vs sync — Pass when: Per scoped file, you note whether it uses async def test_* / await and check project asyncio_mode (strict vs auto); if async, open references/async-testing.md before criticizing async usage.
  3. Fixtures — Pass when: If shared setup matters, you name the conftest.py path(s) or state none; for yield fixtures, confirm cleanup exists before claiming resource leaks.
  4. patch / mocks — Pass when: For any patch or mock critique, you give the import path where the symbol is used (call site), or mark N/A; open references/mocking.md when mocking is central to the review.
  5. Findings — Pass when: Each finding includes a file path and line(s) or test node id, not a generic rule restatement.

Review Checklist

  • Async tests match configured pytest-asyncio mode (strict requires @pytest.mark.asyncio + @pytest_asyncio.fixture; auto discovers async def tests/fixtures automatically)
  • asyncio_default_fixture_loop_scope configured explicitly in pyproject.toml / pytest.ini
  • AsyncMock used for async dependencies (not Mock) and all coroutines/async mocks awaited
  • Background tasks and async resources cleaned up in finally blocks
  • Fixture scope appropriate (function for mutable state, module/session only for immutable/isolated expensive setup)
  • Yield fixtures wrap cleanup in try/finally and use tmp_path instead of hardcoded /tmp paths
  • @pytest.mark.parametrize uses pytest.param(..., id=...) / indirect= cleanly for similar cases
  • patch() targets where the symbol is used (imported/looked up), not where defined
  • Mocks use spec/spec_set and verify exact call arguments when behavior depends on them
  • Tests remain isolated (no shared module-level mock or mutable state)

Valid Patterns (Do NOT Flag)

  • assert without custom message — pytest rewrites assert statements to render detailed diffs automatically
  • @pytest.fixture without explicit scope — Default function scope is correct for most fixtures, including those returning fresh mutable state per test
  • monkeypatch instead of unittest.mock — Simpler pytest-native patching with automatic teardown
  • async def test_* without @pytest.mark.asyncio when asyncio_mode = "auto" — Intentional in auto mode

When to Load References

  • Reviewing async test functions or pytest-asyncio config → references/async-testing.md
  • Reviewing fixtures or conftest.py → references/fixtures.md
  • Reviewing parametrized tests → references/parametrize.md
  • Reviewing mocks and patches → references/mocking.md

Review Questions

  1. Does async test/fixture syntax match the project's pytest-asyncio asyncio_mode (strict vs auto)?
  2. Are fixtures properly scoped with try/finally cleanup and tmp_path?
  3. Can duplicated test cases be simplified with @pytest.mark.parametrize?
  4. Do patch() calls target the call-site namespace, use AsyncMock/spec_set, and verify arguments accurately?

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.