This skill provides focused guidance, code recipes, and a project initializer for pytest. It helps you:
- Add or refactor tests with clear structure and naming
- Use fixtures, parametrization, and marks effectively
- Mock dependencies (monkeypatch, pytest-mock) and isolate IO with
tmp_path - Test async code, CLIs, web apps (FastAPI, Flask, Django), and pandas/SQLAlchemy logic
- Configure coverage, flaky tests, xfail/skip, and CI integration
See SKILL.md for the skill definition, guides.md for quick how‑tos, and recipes.md for copy‑paste patterns.
Codex CLI treats any folder under ~/.codex/skills/ with a valid SKILL.md as a skill.
Clone this repository into your skills directory (example path uses a short folder name):
git clone https://github.com/allthingssecurity/codex-skill-pytest \
~/.codex/skills/pytest-testing
Start Codex with skills enabled and verify:
codex --enable skills -m gpt-5.2
list skills
Expected entry:
- pytest-testing — Create and maintain tests with pytest ...
(file: ~/.codex/skills/pytest-testing/SKILL.md)
Paste one of these into Codex to invoke this skill:
- "Use the pytest-testing skill to initialize pytest with coverage and CI in this folder."
- "Run the pytest-testing skill and add tests for my functions in
src/yourpkg." - "Initialize pytest (pytest.ini, conftest.py, .coveragerc) using the pytest-testing skill and set up a GitHub Actions workflow."
After Codex acknowledges the skill, it will typically run init_pytest.py and scaffold the files.
You can run the initializer script directly from this repo:
python3 skill-pytest/init_pytest.py --ci --package yourpkg
python3 -m pip install -r requirements-dev.txt
pytest -q --cov
Arguments:
--ciadds.github/workflows/python-tests.yml--package yourpkgsets coveragesource = yourpkg--overwriteupdates existing files if present