What problem does it solve?
pytest testing patterns for any Python project: test structure, fixtures, parametrize, unittest.mock (MagicMock, patch), pytest-cov coverage, and best practices. Stack-agnostic — referenced by every Python plugin in the marketplace.
Use this skill to:
- Organise tests with conftest.py shared fixtures and a clear test/src layout.
- Write parametrized tests to cover multiple inputs without duplication.
- Mock external dependencies (HTTP, DB, filesystem) with unittest.mock and monkeypatch.
- Measure and enforce code coverage with pytest-cov.
Do NOT use this skill for:
- Framework-specific test types (Django TestCase / WebTestCase, FastAPI TestClient, Flask test client — see framework plugin skills).
- Language idioms — see python-foundation:python-conventions.
Core Features & Use Cases
- conftest.py — shared fixtures and fixture scopes.
- Fixture scopes: function / module / class / session.
- Parametrize — data-driven tests with pytest.mark.parametrize.
- Monkeypatch — patching attributes and environment during tests.
- unittest.mock — mocking objects and calls for interaction tests.
- tmp_path — temporary filesystem fixtures for file I/O.
- Coverage — integrate pytest-cov to measure and report test coverage.
Quick Start
Run pytest from your project root to execute tests and verify coverage.