python-testing-patterns
Python-Tests mit pytest-Patterns implementieren
也可從以下取得: wshobson
Das Schreiben von Tests für Python-Code kann zeitaufwendig und inkonsistent sein, ohne klare Muster. Diese Skill bietet sofort verwendbare pytest-Patterns für Fixtures, Mocking, asynchronen Code und TDD-Workflows, um Ihnen zu helfen, schnell zuverlässige Test-Suites zu erstellen.
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「python-testing-patterns」。 Write a test for user authentication that checks login success and failure cases
預期結果:
- Test login success with valid credentials
- Test login failure with invalid password
- Test account lockout after multiple failed attempts
- Mock the database query to isolate authentication logic
正在使用「python-testing-patterns」。 Create a pytest fixture for testing file operations with temporary directories
預期結果:
- Use pytest tmp_path fixture for temporary directory
- Create test files with known content
- Verify file creation and deletion
- Clean up files after test completion
正在使用「python-testing-patterns」。 Set up property-based testing for a string manipulation function
預期結果:
- Use hypothesis.given with string strategies
- Test properties like reversibility
- Test length preservation across random inputs
- Generate hundreds of test cases automatically
安全審計
安全This is a documentation-only skill containing educational markdown content about Python testing patterns. The file contains example code snippets for teaching purposes but no executable code that performs network calls, file system access, environment variable manipulation, or command execution. All 'findings' from the static analyzer are false positives caused by the analyzer misinterpreting markdown code fence delimiters as Ruby backticks, and test placeholder strings as actual secrets.
風險因素
🌐 網路存取 (17)
📁 檔案系統存取 (1)
⚙️ 外部命令 (37)
🔑 環境變數 (23)
品質評分
你能建構什麼
Test-Suite einrichten
Neue Test-Infrastruktur mit Fixtures, Mocking und Coverage für Python-Projekte erstellen.
Integrationstests schreiben
Integrationstests für APIs, Datenbanken und externe Services mit pytest-Patterns erstellen.
CI/CD-Tests konfigurieren
Automatisierte Test-Pipelines mit Coverage-Reporting und Test-Markierungen einrichten.
試試這些提示
Write a pytest unit test for a function called calculate_total that takes a list of prices and returns the sum with tax. Include test cases for normal input, empty list, and single item.
Create a pytest fixture for database testing. The fixture should connect to an in-memory SQLite database, create tables, yield a session, then clean up after the test.
Write tests for an API client that fetches user data. Use unittest.mock patch to mock the requests.get call. Test both success and 404 error cases.
Write async tests for a function that fetches data from multiple URLs concurrently using asyncio.gather. Show how to use pytest-asyncio mark and fixtures with async setup.
最佳實務
- Verwenden Sie beschreibende Testnamen, die erklären, was getestet wird und welches Ergebnis erwartet wird
- Halten Sie Tests unabhängig ohne gemeinsamen Status zwischen Testfällen
- Testen Sie Grenzfälle und Fehlerbedingungen, nicht nur den Happy Path
避免
- Vermeiden Sie das Testen mehrerer Assertions in einem einzigen Test, wenn sie separate Tests sein könnten
- Machen Sie Tests nicht von der Ausführungsreihenfolge oder gemeinsamem Status abhängig
- Vermeiden Sie hartcodierte Werte, die aus Fixtures oder Konfiguration stammen sollten