python-testing-patterns
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.
Télécharger le ZIP du skill
Importer dans Claude
Allez dans Paramètres → Capacités → Skills → Importer un skill
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ûrAll 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.
Facteurs de risque
⚙️ Commandes externes (1)
🌐 Accès réseau (1)
🔑 Variables d’environnement (1)
Motifs détectés
Score de qualité
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
Create pytest tests for a function called [FUNCTION_NAME] that [DESCRIPTION]. Use the AAA pattern.
Create pytest fixtures with [SCOPE] scope to provide [RESOURCE] for tests. Include proper setup and teardown.
Write tests that mock [EXTERNAL_SERVICE] calls using unittest.mock. Show both patch decorator and context manager approaches.
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?
How do I mock a function that does not use requests library?
What is fixture scope and when should I use each?
How do I test exceptions with pytest?
What is test-driven development (TDD)?
How do I run only tests matching a keyword?
Détails du développeur
Auteur
sickn33Licence
MIT
Dépôt
https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/python-testing-patternsRéf
main
Structure de fichiers