pytest-codex
Your AGENTS.md says “use uv.” Did Codex actually use it?
Turn agent instructions into pytest assertions. Check the commands Codex ran, the files it changed, and the MCP tools it called. Record a real run once; replay it in CI with zero model calls.
Illustration: a synthetic command trace, rendered from actual pytest failure output. No model call was used to make this image. A separate real recording is included and passes offline.
Start with one test
python -m pip install pytest-codex
The fixture requires 0.1.0+. If your index still serves the 0.0.1 core preview,
install this checkout with python -m pip install ..
Point pytest at the small project you want Codex to work on:
# pyproject.toml
[tool.pytest.ini_options]
codex_project = "sample_repo"
# tests/test_conventions.py
def test_agent_follows_project_rules(codex):
run = codex.exec("Add requests as a project dependency.")
assert run.ran("uv add", ok=True), run
assert not run.ran("pip install"), run
assert run.modified("pyproject.toml"), run
assert not run.modified("legacy/*"), run
# Record once — needs Codex CLI + login and uses model quota.
python -m pytest tests/test_conventions.py --codex-record
# Replay in CI — no Codex binary, credentials, or model calls.
python -m pytest tests/test_conventions.py
Each call gets a fresh project copy. Shell edits count as file changes too. Missing or stale recordings fail with a re-record instruction; the default mode never falls back to a paid call.
Check reliability across attempts
import pytest
@pytest.mark.codex(runs=5, pass_rate=0.8)
def test_dependency_convention(codex):
run = codex.exec("Add requests as a dependency.")
assert run.ran("uv add", ok=True), run
Record five attempts, require four to pass, and save each one separately. Replay checks those saved observations; re-record to measure a new model or CLI version.
Why a pytest plugin?
- A linter checks instruction text. This checks the commands and file changes from an execution, including edits made through shell tools.
- A one-off agent script needs its own test machinery. This fits pytest fixtures, parametrization, failure reports, and your existing CI.
- Calling a model on every PR spends quota. Checked-in recordings let ordinary PR checks replay without model calls. Use explicit live runs for fresh evidence.
Try the included recording
git clone https://github.com/Czj027/pytest-codex.git
cd pytest-codex
python -m pip install .
python -m pytest examples/test_conventions.py --codex-bin=not-installed -q
This is a real Windows recording: successful uv add, changed dependency
declarations, and untouched legacy code. The deliberately missing CLI proves
the example can replay without launching Codex.
Learn more
| Need | Read |
|---|---|
| Commands, files, messages, MCP calls, tokens | Run API |
| Record / replay / live / auto modes | Configuration |
| Repeat semantics and fixture sharing | Repeated runs |
| Windows setup, isolation, privacy, stale recordings | Caveats |
| Contributing and local checks | Development |
run.succeeded means the CLI turn completed; use command status and file
assertions to check the work. Recordings may contain sensitive output, so review
them before committing. MIT licensed; independent community project.
Metadata
Release files for pytest-codex 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytest_codex-0.1.0.tar.gz | 87.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_codex-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 106.2 kB
Release files / pytest_codex-0.1.0.tar.gz
| Download URL | pytest_codex-0.1.0.tar.gz |
|---|---|
| Size | 87.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
706b31dfc6293982bf56d5ebbdf8d122fa4c64ca735ea47ba3e300ba34e02fd8
|
|
BLAKE2b-256 checksum How to use checksums |
97d78f7c3c429846719cfbea4d2cd147c6b021a774f5cbef4ef15952887e106e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pytest_codex-0.1.0-py3-none-any.whl
| Download URL | pytest_codex-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83f63b9e122ae0e6197ff8eec72116188e8a22616904d2526bdfb7d4996f6ff4
|
|
BLAKE2b-256 checksum How to use checksums |
12bb19d2440e360c8389693797ce62cbc4f7e99215538c531f6a2df11648680d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for pytest-codex 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.