pytest
pytest is Python's standard testing framework, enabling developers to write organized unit and integration tests through fixtures for dependency injection and parametrization for data-driven test cases. It supports async code, multiple test discovery patterns, and integrates seamlessly with FastAPI, Django, and Flask, plus a rich plugin ecosystem for coverage, mocking, and parallel execution.
pytest helps you write and organize unit tests for Python code with fixtures, parametrization, and framework integrations.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-07-18
pytest helps you write and organize unit tests for Python code with fixtures, parametrization, and framework integrations. pytest is Python's standard testing framework, enabling developers to write organized unit and integration tests through fixtures for dependency injection and parametrization for data-driven test cases. It supports async code, multiple test discovery patterns, and integrates seamlessly with FastAPI, Django, and Flask, plus a rich plugin ecosystem for coverage, mocking, and parallel execution.
Use it when
- pytest fixtures provide dependency injection for your tests, eliminating setup/teardown boilerplate.
- pytest parametrization lets you run the same test with multiple input sets using @pytest.mark.parametrize.
Verify before relying
Read SKILL.md below before installing (2 files). Open directory: indexed for reading, not audited.
Install
bobmatnyc/claude-mpm-skills/pytest · repository language: Python
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How to write unit tests in Python with pytest?
pytest is Python's standard testing framework that makes writing unit tests straightforward. You create test files (named test_*.py or *_test.py), define test functions starting with test_, and use simple assert statements. pytest automatically discovers and runs these tests. For example: def test_addition(): assert 2 + 2 == 4. pytest's clear syntax and powerful features like fixtures and parametrization make it ideal for organizing tests across small scripts to large applications.
What are pytest fixtures and how do you use them?
pytest fixtures provide dependency injection for your tests, eliminating setup/teardown boilerplate. Define fixtures using @pytest.fixture decorator in conftest.py or your test file, then pass them as function arguments to tests. Fixtures handle database connections, API clients, temporary files, and other resources. pytest manages their lifecycle—creating before tests run and cleaning up after. This approach keeps tests clean, reusable, and maintainable across your test suite.
How can you parametrize tests in pytest?
pytest parametrization lets you run the same test with multiple input sets using @pytest.mark.parametrize. For example: @pytest.mark.parametrize('input,expected', [(2, 4), (3, 9)]) def test_square(input, expected): assert input**2 == expected. This creates separate test runs for each parameter set, reducing code duplication and making data-driven testing simple. Combine parametrization with fixtures for powerful, flexible test scenarios.
How do you test FastAPI, Django, or Flask applications?
pytest integrates seamlessly with FastAPI, Django, and Flask through specialized fixtures and clients. FastAPI uses TestClient; Django provides pytest-django with database fixtures; Flask uses app.test_client(). pytest handles async endpoints natively with pytest-asyncio. Define fixtures for app instances, database setup, and authenticated users, then write tests using pytest's standard patterns. This unified approach works across all three frameworks with minimal framework-specific code.
How do you mock external API calls in pytest?
pytest works with pytest-mock and unittest.mock to mock external dependencies. Use @patch decorators or the mocker fixture to replace API calls with controlled responses. For example: mocker.patch('requests.get', return_value=Mock(json=lambda: {'data': 'test'})). This isolates tests from external services, speeds execution, and ensures reproducible results. Combine mocking with fixtures to create reusable mock setups across your test suite.
How do you generate coverage reports and enforce test quality?
pytest integrates with pytest-cov to generate coverage reports showing which code lines are tested. Run pytest --cov=myapp to measure coverage percentage. Use --cov-fail-under=80 to enforce minimum coverage thresholds and fail builds if coverage drops. Generate HTML reports with --cov-report=html for detailed analysis. pytest's plugin ecosystem and command-line options make it easy to integrate coverage checks into CI/CD pipelines and maintain code quality standards.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
pytest - Professional Python Testing
Overview
pytest is the industry-standard Python testing framework, offering powerful features like fixtures, parametrization, markers, plugins, and seamless integration with
(truncated - see the full file via the links below)
File tree — 2 files
toolchains/python/testing/pytest/SKILL.md
toolchains/python/testing/pytest/metadata.json
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Write and organize unit tests for Python code”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Learn to build robust Python tests using pytest with test-driven development principles. This skill covers fixtures for setup and teardown, parametrization for running tests across multiple inputs, mocking to isolate dependencies, and achieving meaningful code coverage targets.
Learn to build robust test suites using pytest with fixtures at multiple scopes, parameterized test cases, and mocking strategies. This skill covers async testing patterns, FastAPI application testing, and property-based testing approaches to ensure comprehensive coverage and maintainable test code.
Master pytest through test-driven development, fixtures, and mocking strategies. Build comprehensive test suites with parametrized tests, external dependency mocking, and CI/CD pipeline integration while measuring code coverage.
Learn pytest essentials and test-driven development patterns for Python projects. This skill covers fixtures, parametrization, mocking, and coverage strategies to build reliable test suites. Follow the red-green-refactor cycle and achieve 80%+ code coverage on your critical paths.
Master pytest for Python testing with guidance on fixtures, parametrization, markers, and mocking strategies. Learn test organization patterns, coverage best practices, and common commands to streamline your testing workflow.
pytest-skill equips you with patterns for writing robust Python tests using pytest's core features: fixtures for setup and teardown, parametrize for data-driven testing, markers for test organization, and mocking for external dependencies. It covers conftest configuration, exception handling, and best practices for production environments.
More skills pytest (MIT) · Pytest Patterns (unlicensed) · Pytest Patterns (unlicensed) · Pytest Coder (NOASSERTION) · python-testing-patterns (MIT) · python-testing (MIT) · python-testing-patterns (MIT) · Test Frameworks (unlicensed)