Authors pytest modules with conftest fixtures, parametrize, markers, pytest-mock, asyncio, and coverage or xdist runners. Trigger on pytest, conftest, @pytest.fixture, or parametrize. Not for unittest.TestCase-first trees, Jest/Vitest, or coverage-gate configuration alone.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Authors pytest modules with conftest fixtures, parametrize, markers, pytest-mock, asyncio, and coverage or xdist runners. Trigger on pytest, conftest, @pytest.fixture, or parametrize. Not for unittest.TestCase-first trees, Jest/Vitest, or coverage-gate configuration alone.
This skill provides production-grade pytest test generation patterns covering fixtures, parametrize, markers, mocking, conftest, async testing, and CI/CD integration. It targets Python projects using pytest as the primary test runner on Windows (PowerShell) hosts.
When to Use
Use this skill when the user needs to generate, refactor, or debug pytest tests. Trigger keywords and phrases:
pytest
conftest
@pytest.fixture
@pytest.mark
Python test
parametrize
pytest-asyncio
pytest-mock
pytest-cov
pytest-xdist
Do not use this skill for unittest-only projects or non-Python testing frameworks. If the project uses unittest.TestCase classes, prefer plain assert patterns but note that setUp/tearDown methods still work under pytest.
Prerequisites
Python 3.8+ installed and on PATH.
pytest installed in the active environment:
pip install pytest
Recommended plugins (install only what the project needs):
If the project uses pyproject.toml or pytest.ini, ensure test paths and markers are declared there before running marker-filtered commands.
Procedure
1. Identify the test scope
Determine what needs testing: a function, class, module, API endpoint, or integration flow. Check for an existing conftest.py and tests/ directory structure.
2. Create or update conftest.py
Place shared fixtures in tests/conftest.py (or project-root conftest.py for top-level fixtures).
Unregistered markers cause warnings. Always declare custom markers in pyproject.toml under [tool.pytest.ini_options] markers list or in pytest.ini. Unregistered markers trigger PytestUnknownMarkWarning and may be treated as errors with -W error.
assertEqual instead of assert. When using unittest.TestCase subclasses, self.assertEqual works but loses pytest's assertion rewriting. Prefer plain assert in non-TestCase test classes.
Forgetting teardown. A fixture without yield or a try/finally block leaks resources. Always use yield followed by teardown code.
scope="session" fixtures with mutable state. Session-scoped fixtures persist across the entire run. If tests mutate session-scoped data, later tests may see stale state. Use scope="function" or add a reset fixture.
mocker fixture not available.mocker comes from pytest-mock. If the plugin is not installed, mocker will raise a fixture-not-found error. Fall back to unittest.mock.patch as a decorator or context manager.
Windows path issues. Use pathlib.Path or os.path.join instead of hardcoded forward slashes. The tmp_path fixture returns a Path object that works cross-platform.
pytest-xdist and session-scoped fixtures. With -n auto, session-scoped fixtures may be instantiated per-worker. Use scope="session" carefully and consider pytest-xdist's --dist=loadscope to group tests sharing expensive fixtures.
Async tests without pytest-asyncio. A bare async def test_... will be skipped or error. Install pytest-asyncio and either mark the test with @pytest.mark.asyncio or set asyncio_mode = "auto" in config.
Coverage not collected.pytest --cov=myapp requires pytest-cov and the coverage package. Ensure the import path matches the package directory, not the test directory.
Import errors from conftest.py. A conftest.py at the project root that imports application code will fail if the package is not installed in editable mode. Run pip install -e . or ensure PYTHONPATH includes the project root.
Verification
After generating or modifying tests, verify with these checkable commands:
Confirm pytest is installed and collects tests:
pytest --collect-only
Expected: a list of collected test items with no errors.
Run the full suite verbosely:
pytest -v
Expected: each test name printed with PASSED, FAILED, SKIPPED, or XFAIL.
Check for marker warnings:
pytest -W error::pytest.PytestUnknownMarkWarning
Expected: no errors if all markers are registered.
Run with coverage (if configured):
pytest --cov=myapp --cov-report=term-missing
Expected: a coverage summary table showing per-file line coverage and missing line numbers.
Run only the new or modified test file:
pytest tests/test_your_file.py -v
Expected: all tests in that file pass (or show expected xfail/skip).
Verify no fixture leaks (quick smoke):
pytest --lf -v
Expected: previously failed tests re-run; if they now pass, the fix is confirmed.
Related skills
unittest-skill — for projects using unittest.TestCase as the primary framework.
coverage-skill — for advanced coverage configuration and gate enforcement.
github-actions-skill — for CI matrix setup referenced in reference/playbook.md §9.
Limitations
Use this skill only when the task clearly matches its upstream source and local project context.
Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.
Windows (PowerShell) is the primary host. Commands are tested on PowerShell; adjust quoting for bash/zsh if running on WSL or Linux.