python-testing-patterns

Implement pytest test suites with fixtures, mocking, parameterization, and coverage reporting.

1|Updated Mar 13, 2026
One-click install
npx skills add https://github.com/dominionism/Noesis --skill python-testing-patterns-dominionism
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing-patterns
Source: https://github.com/dominionism/Noesis/tree/main/assets/skills/python-testing-patterns
Command: npx skills add https://github.com/dominionism/Noesis --skill python-testing-patterns-dominionism

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires knowing how to structure test suites, isolate dependencies, handle async code, and measure coverage, which is difficult without established patterns. ## Core Features & Use Cases - Pytest Patterns: Provides ready-to-use patterns for fixtures, parameterized tests, exception testing, and monkeypatching environment variables. - Mocking & Async Testing: Covers unittest.mock usage, async test functions with pytest-asyncio, and time control with freezegun. - Coverage & CI Integration: Includes pytest-cov configuration, test markers, and GitHub Actions workflow examples for continuous testing. - Use Case: When building a new API client, use this Skill to generate unit tests that mock HTTP requests, parametrize input validation cases, and verify retry logic on transient failures. ## Quick Start Write pytest tests for my Python module using fixtures, mocking for external API calls, and parameterized cases for edge inputs.

Frequently Asked Questions about python-testing-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests with pytest in Python?▼

Write test functions prefixed with test_ and use plain assert statements to verify behavior. Follow the Arrange-Act-Assert pattern: set up test data, execute the code under test, then verify the results. Run tests with the pytest command.

How to mock API requests in Python tests?▼

Use unittest.mock's patch function to replace requests.get or requests.post with a Mock object whose return_value simulates the HTTP response. Configure mock_response.json.return_value with your expected data and assert the mock was called with the correct URL.

What is the difference between pytest fixtures and setup methods?▼

Pytest fixtures are declared with the @pytest.fixture decorator and injected into tests as parameters, supporting scopes like function, module, and session. They use yield to separate setup from teardown, offering more flexibility than xUnit-style setUp/tearDown methods.

Does pytest support testing async functions?▼

Yes, pytest supports async tests through the pytest-asyncio plugin. Mark async test functions with @pytest.mark.asyncio and use await inside the test. Async fixtures can also be defined with yield for setup and teardown of async resources.

How do I measure test coverage with pytest?▼

Install pytest-cov and run pytest with the --cov flag targeting your package, such as pytest --cov=myapp tests/. Add --cov-report=term-missing to see uncovered lines and --cov-fail-under=80 to enforce a minimum coverage threshold.

Why do my tests fail when run together but pass individually?▼

This indicates shared state between tests, violating test isolation. Use fixtures with function scope to reset state, monkeypatch to safely modify environment variables, and tmp_path for file operations so each test cleans up after itself.