技能 python-testing-patterns
🧪
撰寫 Python 測試可能很耗時,且團隊間的實作方式不一致。本技能提供清晰的 pytest 模式和範例,可加速測試設計並提高覆蓋率。
支援: Claude Codex Code(CC)
1
下載技能 ZIP
2
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
3
開啟並開始使用
測試它
正在使用「python-testing-patterns」。 I need tests for a service that calls an API and caches results
預期結果:
- Create a fixture for the service with a temporary cache
- Mock the HTTP client and assert it is called once
- Add a second call test to confirm cached behavior
正在使用「python-testing-patterns」。 Write a test for a division function that handles zero
預期結果:
- Use pytest.raises to check ZeroDivisionError is raised
- Add a test case for normal division
- Assert the error message matches expected text
正在使用「python-testing-patterns」。 How do I test email validation with many inputs
預期結果:
- Use @pytest.mark.parametrize with test email cases
- Include valid and invalid examples
- Run all cases with single test function
安全審計
安全v4 • 1/17/2026
Pure documentation skill containing only instructional examples for Python testing patterns. No executable code, scripts, or network operations in the skill logic itself. Static findings are false positives from example code blocks in documentation.
2
已掃描檔案
1,084
分析行數
3
發現項
4
審計總數
風險因素
🌐 網路存取 (17)
⚙️ 外部命令 (37)
SKILL.md:48-63 SKILL.md:63-69 SKILL.md:69-125 SKILL.md:125-129 SKILL.md:129-201 SKILL.md:201-205 SKILL.md:205-250 SKILL.md:250-254 SKILL.md:254-322 SKILL.md:322-326 SKILL.md:326-363 SKILL.md:363-369 SKILL.md:369-411 SKILL.md:411-415 SKILL.md:415-459 SKILL.md:459-463 SKILL.md:463-513 SKILL.md:513-517 SKILL.md:517-569 SKILL.md:569-573 SKILL.md:573-615 SKILL.md:615-621 SKILL.md:621-633 SKILL.md:633-637 SKILL.md:637-665 SKILL.md:665-669 SKILL.md:669-708 SKILL.md:708-712 SKILL.md:712-727 SKILL.md:727-731 SKILL.md:731-800 SKILL.md:800-804 SKILL.md:804-839 SKILL.md:839-843 SKILL.md:843-861 SKILL.md:861-863 SKILL.md:863-885
🔑 環境變數 (23)
審計者: claude 查看審計歷史 →
品質評分
38
架構
100
可維護性
85
內容
21
社群
100
安全
83
規範符合性
你能建構什麼
強化單元測試
應用 pytest 模式來為核心業務邏輯建立清晰、可維護的測試。
標準化測試套件
使用 fixture、標記和參數化來建立一致的測試基礎設施。
驗證資料工具程式
為資料處理函式新增單元測試和屬性檢查。
試試這些提示
基本單元測試
使用 Arrange Act Assert 模式,為一個將兩個數字相加的函式撰寫簡單的 pytest 測試。
Fixture 設定
建立一個用於資料庫用戶端的 pytest fixture,並展示一個使用它且具有適當解構的測試。
模擬 HTTP 呼叫
提供一個模擬 requests.get 並斷言 URL 和參數的 pytest 範例。
非同步和屬性測試
展示如何測試非同步函式,並為字串工具程式新增一個 Hypothesis 屬性測試。
最佳實務
- 保持測試隔離並清理共用狀態
- 使用 fixture 進行可重複使用的設定和解構
- 參數化測試以用最少的重複覆蓋邊界情況
避免
- 在測試之間共用可變的全域狀態
- 在單元測試中存取即時外部服務
- 在一個測試中斷言多種行為
常見問題
Which Python versions are supported
範例針對現代 Python 和 pytest,通常是 3.9 或更新版本。
What test types are covered
專注於單元、整合、非同步和屬性測試模式。
Can it integrate with CI pipelines
它提供您可以改編用於 CI 的 pytest 和覆蓋率指令。
Does it access my data or files
不會。它僅提供指導和範例程式碼。
How do I get help with failing tests
分享失敗的輸出和最少的程式碼片段以獲得針對性的建議。
How does it compare to generic advice
它提供具體的 pytest 模式、fixture 和模擬範例。