Compétences python-testing-patterns
📦

python-testing-patterns

Sûr ⚙️ Commandes externes🌐 Accès réseau🔑 Variables d’environnement

Write Better Python Tests

Également disponible depuis: 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.

Prend en charge: Claude Codex Code(CC)
🥉 75 Bronze
1

Télécharger le ZIP du skill

2

Importer dans Claude

Allez dans Paramètres → Capacités → Skills → Importer un skill

3

Activez et commencez à utiliser

Tester

Utilisation de "python-testing-patterns". Write tests for a calculate_discount function that takes price and discount_percentage, returns discounted price

Résultat attendu:

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

Utilisation de "python-testing-patterns". Create fixtures for testing a database connection with session scope

Résultat attendu:

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

Utilisation de "python-testing-patterns". Mock HTTP requests to an API client that fetches user data

Résultat attendu:

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

Audit de sécurité

Sûr
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
Fichiers analysés
947
Lignes analysées
3
résultats
1
Total des audits

Facteurs de risque

⚙️ Commandes externes (1)
🌐 Accès réseau (1)
🔑 Variables d’environnement (1)

Motifs détectés

External Commands DocumentationNetwork Mocking ExamplesTest Fixture Configurations
Audité par: claude

Score de qualité

38
Architecture
100
Maintenabilité
87
Contenu
50
Communauté
100
Sécurité
100
Conformité aux spécifications

Ce que vous pouvez construire

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

Essayez ces prompts

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].

Bonnes pratiques

  • 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

Éviter

  • 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

Foire aux questions

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.

Détails du développeur

Structure de fichiers