跳到正文
Skillpedia
测试48k · #5553

python-testing-patterns

它能做什么

这份指南教你如何全面测试 Python 代码。内容涵盖 “pytest” 的使用、创建 “fixtures”(预先设置好的测试环境)、“mocking”(模拟部分代码),以及测试驱动开发(TDD)的实践方法。

适用场景

  • ✓为 Python 代码编写测试时。
  • ✓搭建和组织测试套件时。
  • ✓采用 TDD 方式开发时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/python-testing-patterns/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/python-testing-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我怎样为一个计算列表平均值的 Python 函数编写测试?”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会依据这份指南,演示如何编写高效的 Python 测试。它会讲解 pytest 等工具的用法,以及模拟依赖项的技巧,帮助你确保代码运行正确。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Python Testing Patterns

Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.

Use this skill when

  • Writing unit tests for Python code
  • Setting up test suites and test infrastructure
  • Implementing test-driven development (TDD)
  • Creating integration tests for APIs and services
  • Mocking external dependencies and services
  • Testing async code and concurrent operations
  • Setting up continuous testing in CI/CD
  • Implementing property-based testing
  • Testing database operations
  • Debugging failing tests

Do not use this skill when

  • The task is unrelated to python testing patterns
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open resources/implementation-playbook.md.

Resources

  • resources/implementation-playbook.md for detailed patterns and examples.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题

什么是 “pytest”?

“pytest” 是一款很流行的工具,能让编写 Python 代码的测试变得更简单。

什么是 “fixtures”?

“Fixtures” 就像初始设置,可以在多个测试之间复用,用来准备测试环境。

什么是 “mocking”?

“Mocking” 是一种技术,用来模拟你的代码的某些部分,或者代码所依赖的外部服务,这样就能单独测试某个单元。

详情

作者的原始描述

Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5553
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能