スキル python-testing-patterns
📦

python-testing-patterns

安全 ⚙️ 外部コマンド🌐 ネットワークアクセス🔑 環境変数

Write Better Python Tests

こちらからも入手できます: wshobson,ActiveInferenceInstitute

Writing maintainable tests is challenging. This skill provides comprehensive pytest patterns including fixtures, mocking, parameterization, and TDD workflows to help you build reliable test suites.

対応: Claude Codex Code(CC)
🥉 75 ブロンズ
1

スキルZIPをダウンロード

2

Claudeでアップロード

設定 → 機能 → スキル → スキルをアップロードへ移動

3

オンにして利用開始

テストする

「python-testing-patterns」を使用しています。 Write tests for a calculate_discount function that takes price and discount_percentage, returns discounted price

期待される結果:

Basic test file with multiple test cases covering normal discounts, zero discount, and invalid inputs

「python-testing-patterns」を使用しています。 Create fixtures for testing a database connection with session scope

期待される結果:

Fixture setup with proper yield/teardown pattern for database resource management

「python-testing-patterns」を使用しています。 Mock HTTP requests to an API client that fetches user data

期待される結果:

Tests using patch() to mock requests.get with different response scenarios

セキュリティ監査

安全
v1 • 2/24/2026

All 87 static findings are false positives. The detected patterns (external_commands, network, env_access) are documentation examples of pytest commands, HTTP mocking patterns, and test fixture configurations - all legitimate testing education content. No actual security threats present.

2
スキャンされたファイル
947
解析された行数
3
検出結果
1
総監査数

リスク要因

⚙️ 外部コマンド (1)
🌐 ネットワークアクセス (1)
🔑 環境変数 (1)

検出されたパターン

External Commands DocumentationNetwork Mocking ExamplesTest Fixture Configurations
監査者: claude

品質スコア

38
アーキテクチャ
100
保守性
87
コンテンツ
50
コミュニティ
100
セキュリティ
100
仕様準拠

作れるもの

New Python Project Testing Setup

Set up a complete test suite for a new Python project with fixtures, conftest.py configuration, and CI/CD integration

Legacy Code Test Coverage

Add tests to existing untested code using mocking to isolate units and parameterization to cover edge cases

API Integration Testing

Write integration tests for REST APIs using fixtures for test data and mocking for external service calls

これらのプロンプトを試す

Basic Test Creation
Create pytest tests for a function called [FUNCTION_NAME] that [DESCRIPTION]. Use the AAA pattern.
Fixture Setup
Create pytest fixtures with [SCOPE] scope to provide [RESOURCE] for tests. Include proper setup and teardown.
Mocking External Calls
Write tests that mock [EXTERNAL_SERVICE] calls using unittest.mock. Show both patch decorator and context manager approaches.
Parameterized Testing
Create parameterized tests for [FUNCTION] using pytest.mark.parametrize to test [EDGE_CASES].

ベストプラクティス

  • Use descriptive test names that explain what is being tested and expected behavior
  • Keep tests independent with proper setup/teardown - no shared state between tests
  • Follow AAA pattern: Arrange (setup), Act (execute), Assert (verify) clearly separated

回避

  • Avoid test names like test_1 or test_function that do not describe the test purpose
  • Do not mix multiple assertions in one test when they could be separate tests
  • Avoid testing implementation details instead of behavior - test what the code does, not how

よくある質問

What is the difference between unit tests and integration tests?
Unit tests test individual functions or classes in isolation. Integration tests test how multiple components work together, such as testing API endpoints with a real database.
How do I mock a function that does not use requests library?
Use unittest.mock.patch decorator or context manager to replace any function or class with a Mock object. Import the function path as a string: @patch('module.function_name').
What is fixture scope and when should I use each?
Function scope (default) creates fixture for each test. Class scope once per test class. Module scope once per module. Session scope once per entire test session. Use session/module for expensive resources.
How do I test exceptions with pytest?
Use pytest.raises() as a context manager: with pytest.raises(ExpectedException): your_function(). Optionally pass match parameter to check exception message.
What is test-driven development (TDD)?
TDD is a development approach where you write tests before code. Cycle: Write failing test (red), write minimal code to pass (green), refactor code (refactor). Helps ensure testable design.
How do I run only tests matching a keyword?
Use pytest -k flag: pytest -k 'test_name_pattern' runs only tests with names matching the pattern. Use pytest -m marker to run tests with specific markers.

開発者の詳細

ファイル構成