Reusable pytest results ingestion tooling with database export and CLI helpers.
Project description
pytest-chronicle
Reusable tooling for capturing pytest results, ingesting them into a relational database, and querying the latest failures. This package is being extracted from Survi's in-repo helpers so it can stand alone in other projects.
Features (current snapshot)
- Pytest plugin (
pytest_chronicle.pytest_plugin) that streams per-test JSONL records. - Async ingestion module that stamps runs with Git/CI metadata and persists them to SQLite or Postgres via SQLModel.
- Console entry point (
pytest-chronicle) with subcommands for:run: execute pytest underuv, capture JSONL + JUnit artifacts, and optionally ingest the run.ingest: loadsummary.jsonor JSONL artifacts into the database.latest-red: list the latest failing/erroring tests for a project/suite.backfill: ingest historicalsummary.jsonfiles in bulk.export-sqlite/import-sqlite: migrate data between database backends.db: drive Alembic migrations (upgrade,downgrade,current,history,stamp,revision).
- Thin shims in
tools/test_results/re-export the new package so existing Make targets remain intact during migration.
Installation (monorepo local path)
UV_CACHE=.uv_cache uv pip install -e tools/pytest-chronicle
The package declares sqlalchemy, sqlmodel, aiosqlite, asyncpg, and alembic as core dependencies, with a dev extra providing pytest and ruff.
CLI quickstart
$ pytest-chronicle run packages/survi -- suite -k smoke
$ pytest-chronicle ingest --summary packages/survi/.artifacts/test-results/summary.json
$ pytest-chronicle latest-red --project-like "packages/survi%"
$ pytest-chronicle backfill --glob packages/survi/reports/*/summary.json
$ pytest-chronicle export-sqlite --database-url sqlite+aiosqlite:///test_results.db --out export.sqlite
$ pytest-chronicle import-sqlite --sqlite export.sqlite --database-url postgresql+asyncpg://user:pass@localhost/db
$ pytest-chronicle db --database-url sqlite+aiosqlite:///test_results.db upgrade head
All commands honour PYTEST_RESULTS_DB_URL, TEST_RESULTS_DATABASE_URL, or SCS_DATABASE_URL when --database-url is omitted. SQLite targets default to <repo>/test_results.db.
Monorepo Makefile toggle
Set PYTEST_RESULTS_DRIVER=cli to run existing Make targets (e.g., make ci-matrix, make survi-test) through the Python CLI instead of the legacy shell wrappers while we validate the new tooling.
Pytest plugin usage
The package exposes a pytest11 entry point, so simply installing it makes the plugin available to any pytest run—no extra flags required. Typical setup:
[pytest]
addopts = --results-jsonl=.artifacts/test-results/results.jsonl
What happens:
- each test run emits per-test JSON lines to the configured path (directories are created automatically)
- you can point to an HTTP endpoint instead/also via
--results-endpoint=https://... - optional env vars (
PYTEST_RESULTS_PROJECT,PYTEST_RESULTS_SUITE,PYTEST_RESULTS_DB_URL) provide defaults when you later ingest the run
To ingest the data after a standard pytest invocation, run:
pytest-chronicle ingest --jsonl .artifacts/test-results/results.jsonl \
--project my-project --suite pytest-smoke
The CLI will resolve database credentials using PYTEST_RESULTS_DB_URL / TEST_RESULTS_DATABASE_URL / SCS_DATABASE_URL, or fall back to <repo>/test_results.db when nothing is set.
Developing / Testing
PYTHONPATH=$PWD/tools/pytest-chronicle/src \
uv run --python 3.12 --with pytest --with sqlmodel --with sqlalchemy \
--with aiosqlite --with asyncpg --with alembic \
python -m pytest \
tests/test_jsonl_ingest_phases.py \
tests/test_test_results_queries.py \
tools/pytest-chronicle/tests/unit/test_cli_commands.py \
tools/pytest-chronicle/tests/integration/test_pytest_plugin_autoload.py -q
The CLI tests verify ingestion flows, database helpers, and Alembic commands without touching GPU-heavy suites.
Roadmap
- Harden configuration surface (pyproject/pytest.ini integration, env overrides).
- Publish Alembic migrations as package data and document upgrade paths for new consumers.
- Finalize documentation, Makefile integration, and packaging story for adoption outside Survi.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_chronicle-0.0.1.tar.gz.
File metadata
- Download URL: pytest_chronicle-0.0.1.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbcf5a92db76fb51778a0616d65734cf1aafcb5cac3ddf8a633f4db4f07cb624
|
|
| MD5 |
fefc5782c3f115d8526cfe28eb07b608
|
|
| BLAKE2b-256 |
a69a57d4addc73220c9383f38909d4f854783307902d3aafb75e8f4f6c9cdd72
|
File details
Details for the file pytest_chronicle-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pytest_chronicle-0.0.1-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09940fe7a91c5a15e9244dce511ef980541fbdef674b13336eb189c1cdf70e66
|
|
| MD5 |
a1124836e3382223babd99e51361791d
|
|
| BLAKE2b-256 |
59537f6ba4eaef03c295ba39f61f5173ae811a087a257e40a87124f056a93eb9
|