python-testing-patterns
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.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- python-testing-patterns
- metadata
- { "skill-graph-id": "plugin/10x-swe/python-testing-patterns", "skill-graph-uses": "", "skill-graph-used-by": "" }
- description
- 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.
02 资源文件 39
- 其他.build-trigger25 B
- 参考文档articles/eu-106b-ukraine-loan-us-aid-drops.md3.1 KB
- 参考文档articles/gray-whale-crisis-climate-change-san-francisco-bay.md6.4 KB
- 参考文档articles/hungary-orban-steps-down-historic-electoral-defeat.md3.4 KB
- 参考文档articles/iran-strait-hormuz-closure-travel-impact.md6.6 KB
- 参考文档articles/iran-us-tensions-hormuz-strait-closure-global-trade.md6.1 KB
- 参考文档articles/mark-allen-crucible-comeback-defeats-zhang-anda.md6.3 KB
- 参考文档articles/ravens-exercise-zay-flowers-fifth-year-option.md2.9 KB
- 参考文档articles/satellite-images-reveal-massive-oil-spills-iran-conflict.md3.3 KB
- 参考文档articles/security-breach-disrupts-white-house-correspondents-dinner.md2.9 KB
- 参考文档articles/sidemen-fc-charity-match-wembley-record-fundraising.md6.1 KB
- 参考文档articles/spacex-final-gps-iii-satellite-launch-space-force.md3.3 KB
- 参考文档articles/strait-hormuz-tensions-us-boards-iranian-oil-ship.md3.1 KB
- 参考文档articles/supreme-court-leaks-institutional-crisis-roberts.md6.5 KB
- 参考文档articles/uk-police-probe-iran-linked-group-jewish-site-attacks.md3.2 KB
- 参考文档articles/us-envoys-pakistan-iran-diplomatic-uncertainty.md3.2 KB
- 资产文件assets/.gitkeep—
- 资产文件assets/images/alpine-divorce-trend-dangerous-partner-abandonment-mountains.png1.3 MB
- 资产文件assets/images/essential-digital-tools-summer-2026-flight-disruptions.png1.1 MB
- 资产文件assets/images/eu-106b-ukraine-loan-us-aid-drops.png973.5 KB
- 资产文件assets/images/europe-best-sport-cities-2026-rankings.png1012.0 KB
- 资产文件assets/images/gray-whale-crisis-climate-change-san-francisco-bay.png1.2 MB
- 资产文件assets/images/hungary-orban-steps-down-historic-electoral-defeat.png1.1 MB
- 资产文件assets/images/iran-strait-hormuz-closure-travel-impact.png1.4 MB
- 资产文件assets/images/iran-us-tensions-hormuz-strait-closure-global-trade.png1.4 MB
- 资产文件assets/images/japan-cherry-blossom-overtourism-residents-fight-back.png1.5 MB
- 资产文件assets/images/mark-allen-crucible-comeback-defeats-zhang-anda.png1.0 MB
- 资产文件assets/images/ravens-exercise-zay-flowers-fifth-year-option.png1.3 MB
- 资产文件assets/images/satellite-images-reveal-massive-oil-spills-iran-conflict.png1.6 MB
- 资产文件assets/images/security-breach-disrupts-white-house-correspondents-dinner.png1.5 MB
- 资产文件assets/images/sidemen-fc-charity-match-wembley-record-fundraising.png1.3 MB
- 资产文件assets/images/spacex-final-gps-iii-satellite-launch-space-force.png1.3 MB
- 资产文件assets/images/strait-hormuz-tensions-us-boards-iranian-oil-ship.png1.6 MB
- 资产文件assets/images/supreme-court-leaks-institutional-crisis-roberts.png1.7 MB
- 资产文件assets/images/us-envoys-pakistan-iran-diplomatic-uncertainty.png1.1 MB
- 资产文件assets/images/vogue-hawaii-airbnb-guide-luxury-budget-stays.png1.9 MB
- 参考文档dedup-index.json2.2 KB
- 参考文档references/patterns.md25.3 KB
- 参考文档site.yaml948 B
03 SKILL.md 正文
Python Testing Patterns
Use this skill to test Python behavior with pytest, fixtures, mocks, and property-based tests. Follow the project's test commands, supported Python versions, and configuration.
Workflow
- Read the behavior contract and nearby tests. Identify the regression, boundary, or integration risk the test must detect.
- Select the smallest useful level: unit tests for isolated behavior; integration tests for component contracts; end-to-end tests for complete user flows.
- Arrange explicit inputs, execute the behavior, and assert observable outcomes. Cover relevant edge cases and failures. Several assertions may describe one behavior; do not split them merely to meet an assertion count.
- Isolate state with fixtures,
tmp_path, and environment overrides. Use teardown even when the test fails. Scope shared fixtures carefully; avoid hidden dependencies between tests. - Mock external boundaries rather than the implementation being tested. Patch where the dependency is looked up. Verify real integrations separately when mocks cannot establish the contract.
- Run the focused tests, then required project checks. Report actual commands and results, including skipped tests and unavailable services. Coverage identifies gaps; it does not establish correctness.
Choose a reference
Open only the relevant section of detailed patterns:
- Fundamental Patterns: pytest, fixtures, parameterization, mocking, and exceptions.
- Advanced Patterns: async tests, monkeypatch, temporary files, shared fixtures, and Hypothesis.
- Testing Best Practices: naming, retry limits, time control, markers, and coverage.
- Testing Database Code: sessions, queries, and constraints.
- CI/CD Integration and Configuration Files: suite configuration and CI examples.
The preserved examples are not production-ready templates. In particular, the email validator contradicts one test case; async fixture behavior depends on pytest-asyncio mode; database sessions need failure-safe teardown. Verify installed plugin behavior and current CI action versions before adaptation.
Acceptance
A useful test fails when its target behavior breaks, passes with the correction, and does not depend on unrelated machine state. Never weaken assertions, hide a failure with a skip, or exclude coverage solely to obtain a passing result. Do not install plugins or contact external services merely because an example does so.
04 同仓库更多 Skills
turnstile-spin
Set up Cloudflare Turnstile end-to-end in a project. Scan the codebase, create the widget via the Cloudflare API, embed it where user requests need bot verification (form submissions, SPA actions, API endpoints, download links, comment or vote submissions, etc.), wire canonical server-side siteverify in the customer's existing backend, validate, and persist the skill. Load this when a user asks to add Turnstile, set up CAPTCHA, protect a form or endpoint from bots, or fix a Turnstile integration. Uses Cloudflare's documented Turnstile contract.
frontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
source-insights
Prepare inspected source evidence, preserve exact citations, and publish reviewed insights into an explicit local library.
skill-graph
Discover skills and workflows through independent lexical search, relationship paths and a terminal graph.
session-search
Recall public session turns with exact provenance, bounded excerpts and independent piped exports.
newsletter
Produce a private local AI newsletter from bounded public research, with cited deep dives, HTML/Markdown output, Dagu scheduling and seven-day retention.