← 返回
未分类 中文

Pytest Code Review

Reviews pytest test code for async patterns, fixtures, parametrize, and mocking. Use when reviewing test_*.py files, checking async test functions, fixture u...
审查 pytest 测试代码中的异步模式、fixtures、parametrize 和 mock。适用于检查 test_*.py 文件中的异步测试函数、fixture 使用等。
anderskev anderskev 来源
未分类 clawhub v1.1.1 2 版本 100000 Key: 无需
★ 0
Stars
📥 424
下载
💾 7
安装
2
版本
#latest

概述

Pytest Code Review

Quick Reference

Issue TypeReference
-----------------------
async def test_*, AsyncMock, await patternsreferences/async-testing.md
conftest.py, factory fixtures, scope, cleanupreferences/fixtures.md
@pytest.mark.parametrize, DRY patternsreferences/parametrize.md
AsyncMock tracking, patch patterns, when to mockreferences/mocking.md

Review gates

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

  1. Scoped filesPass when: You list every test_*.py and any conftest.py you will cite; no findings for files outside that list.
  2. Async vs syncPass when: Per scoped file, you note whether it uses async def test_* / await; if yes, open references/async-testing.md before criticizing async usage.
  3. FixturesPass 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 / mocksPass 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. FindingsPass when: Each finding includes a file path and line(s) or test node id, not a generic rule restatement.

Review Checklist

  • [ ] Test functions are async def test_* for async code under test
  • [ ] AsyncMock used for async dependencies, not Mock
  • [ ] All async mocks and coroutines are awaited
  • [ ] Fixtures in conftest.py for shared setup
  • [ ] Fixture scope appropriate (function, class, module, session)
  • [ ] Yield fixtures have proper cleanup in finally block
  • [ ] @pytest.mark.parametrize for similar test cases
  • [ ] No duplicated test logic across multiple test functions
  • [ ] Mocks track calls properly (assert_called_once_with)
  • [ ] patch() targets correct location (where used, not defined)
  • [ ] No mocking of internals that should be tested
  • [ ] Test isolation (no shared mutable state between tests)

When to Load References

  • Reviewing async test functions → async-testing.md
  • Reviewing fixtures or conftest.py → fixtures.md
  • Reviewing similar test cases → parametrize.md
  • Reviewing mocks and patches → mocking.md

Review Questions

  1. Are all async functions tested with async def test_*?
  2. Are fixtures properly scoped with appropriate cleanup?
  3. Can similar test cases be parametrized to reduce duplication?
  4. Are mocks tracking calls and used at the right locations?

版本历史

共 2 个版本

  • v1.1.1 当前
    2026-05-03 07:25 安全 安全
  • v1.1.0
    2026-03-31 05:24

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 199 📥 68,364
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 688 📥 331,744
dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 42,216