{"enrichment":{"faq":[{"a":"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.","q":"How to write unit tests in Python with pytest?"},{"a":"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\u2014creating before tests run and cleaning up after. This approach keeps tests clean, reusable, and maintainable across your test suite.","q":"What are pytest fixtures and how do you use them?"},{"a":"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.","q":"How can you parametrize tests in pytest?"},{"a":"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.","q":"How do you test FastAPI, Django, or Flask applications?"},{"a":"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.","q":"How do you mock external API calls in pytest?"},{"a":"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.","q":"How do you generate coverage reports and enforce test quality?"}],"shadow_tags":["test-automation","dependency-injection","data-driven-testing","test-isolation","assertion-introspection","plugin-ecosystem","test-discovery","ci-cd-integration","fixture-composition"],"summary_rewrite":"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."},"files":[{"bytes":33891,"path":"toolchains/python/testing/pytest/SKILL.md","sha256":"189d7e1a9a0c3cfe5333ad80e74fc284274b8e86cf73f981a4df920cd8942bda","url":"https://skillfed.io/files/bobmatnyc/claude-mpm-skills/pytest/7cbc7d9f/SKILL.md"}],"id":"bobmatnyc/claude-mpm-skills/pytest","links":{"html":"https://skillfed.io/bobmatnyc/claude-mpm-skills/pytest","md":"https://skillfed.io/bobmatnyc/claude-mpm-skills/pytest.md","repo":"https://github.com/bobmatnyc/claude-mpm-skills"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":18,"language":"Python","last_updated":"2026-07-18","license":"MIT","name":"pytest","publisher":"bobmatnyc","stars":62},"relations":{"similar":[{"id":"xu-xiang/everything-claude-code-zh/python-testing"},{"id":"affaan-m/ECC/python-testing"},{"id":"JosiahSiegel/claude-plugin-marketplace/python-testing"},{"id":"hieutrtr/ai1-skills/pytest-patterns"},{"id":"manutej/luxor-claude-marketplace/pytest-patterns"},{"id":"pluginagentmarketplace/custom-plugin-python/pytest-testing"},{"id":"xu-xiang/everything-claude-code-zh/django-tdd"},{"id":"affaan-m/ECC/django-tdd"},{"id":"HermeticOrmus/LibreUIUX-Claude-Code/python-testing-patterns"},{"id":"manutej/luxor-claude-marketplace/pytest"}]},"slug":{"owner":"bobmatnyc","repo":"claude-mpm-skills","skill":"pytest"},"version":"7cbc7d9f"}
