Skip to main content

test-timings

How long did each test take, how much longer will this run need, and did anything get slower? One SQLite file, one script, no dependencies.

A test runner logs a line per finished test:

timing: <class>#<test> <millis>ms <passed|failed>

and, from a test that times its own parts:

step:<name> <millis>ms

timings.py turns those lines into three things a harness can act on: a progress and ETA line it can print while it runs, a history of every test's durations, and a regression gate that fails a run when a test took much longer than its own recent median.

$ python3 timings.py eta --class suite.e2e --run 1699999999 --log run.log \
      --order "pty tui session" --started 1699999990
eta: 1/3 done, 1m02s spent, 2m05s left, 3m07s total, now tui, finish 14:32:05, 8 run(s) of history

Why a log line and not a test-framework plugin

Every runner can print a line, and a line is the only interface this needs: no imports, no conftest, no adapter per framework. The Android suite that this came from writes the line from a shell function and from a JUnit SuiteRunner alike, and both end up in the same database. step: lines are optional and only make steps more useful.

Lines are matched anywhere in a line of the log, so the runner may prefix them with its own indentation or timestamps. A step: line belongs to the test whose timing: line follows it.

Commands

command what it answers
record --log F --run R store this run's lines; the suite calls it after every phase, so the file is always current
eta --class C --run R how much of the run is done, what is left, when it should finish
history [--class C] every test's run count, median, p90, min, max and last outcome
steps [--run R] where the time inside each test of one run went
check --log F --run R the gate: exit 1 if a test was much slower than its median

--run is any identifier the caller likes (an epoch second, a CI run id). Rows are unique per (run, test), so re-reading a log that grew is safe and repeats nothing.

The estimate

What is left is the sum of the medians of each remaining test's last five runs — all of history would make the estimate lag behind a suite that got faster by as many runs as it has ever had. A test with no runs yet is estimated at the class median, or 10 s if it is the class's only test.

What has been spent is the run's wall clock (--started, epoch seconds, or --elapsed, seconds) when the caller knows it, so an install or a setup the run pays before its first test is in the estimate instead of showing up at the end; without either flag it is the sum of the tests already recorded.

--order is the run's list of tests in the order it will run them. That is the only way to name the test in progress, to count a test the history has never seen, and to keep the remaining tests in the order they will actually run.

The gate

$ python3 timings.py check --log run.log --run 1699999999
regression: tui-symbols 14.2s, median 9.8s, allowed 13.8s (+45%)

A test is judged only after it has run at least once before, and only if its median is at least --min-ms (3 s by default): a two-second test moving by four hundred milliseconds is the machine, not the code. The allowance is median * (1 + --max-regression/100) + --slack-ms, 20% and 2 s by default — percent alone is a bad gate on a shared runner, where a four-second test's 20% is less than its own jitter.

The log is read, not ingested: the run being judged has to be compared with what the suite cost before it, and a database that already held this run would drag the median towards the very number under test.

The database

.timings.db in the working directory. --db on either side of the subcommand, or TEST_TIMINGS_DB in the environment, names another file. It is plain SQLite (timings and steps tables), so any client can query it and a CI job can cache it between runs to keep the history that the gate compares against.

Install

pip install test-timings

test-timings --version      # test-timings 0.2.0
test-timings history

Python 3.10 or newer; standard library only, no dependencies. The distribution is test-timings, the module is test_timings, and the command is test-timings, so nothing shadows the timings name that another package already has.

Without pip, the file on its own is still the whole tool — copy test_timings.py next to your test scripts and call it:

python3 test_timings.py history

or, in CI, fetch the file from a pinned release and check it:

curl -fsSLO https://raw.githubusercontent.com/MBanucu/test-timings/v0.2.0/test_timings.py
python3 test_timings.py check --log run.log --run "$CI_RUN_ID"

Tests

python3 -m unittest discover -s tests

CI runs them on 3.10, 3.12 and 3.13, then builds the sdist and the wheel, installs each into its own virtualenv and runs the installed command, because the tests against the checkout would not notice packaging that ships the wrong thing.

Releasing

The version is in test_timings.__version__, and pyproject.toml takes it from there, so there is one number to change. Tag that number:

git commit -am "0.2.0" && git tag -a v0.2.0 -m "0.2.0" && git push origin main v0.2.0

The tag runs .github/workflows/release.yml, which refuses a tag that disagrees with the module, tests, builds, installs the wheel, and uploads to PyPI with trusted publishing — no token is stored in this repository. PyPI has to trust the workflow once:

  • Project: test-timings (for the first upload, a pending publisher with these fields is what creates it)
  • Owner: MBanucu, repository: test-timings
  • Workflow: release.yml, environment: pypi

Licence

GPL-3.0, the same as the suite this was extracted from. See LICENSE.

Metadata

Release files for test-timings 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for test-timings 0.2.0
File Size Uploaded Provenance Actions
test_timings-0.2.0.tar.gz 24.0 kB With provenance Details for test_timings-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for test-timings 0.2.0
File Interpreter ABI Platform Actions
test_timings-0.2.0-py3-none-any.whl Python 3 none any Details for test_timings-0.2.0-py3-none-any.whl

Total release size: 46.4 kB

Release files / test_timings-0.2.0.tar.gz

Download URL test_timings-0.2.0.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f0d43b243e888e8e87078a870b619017d5db3298b4c946ffd7330d0034a1c276
BLAKE2b-256 checksum
How to use checksums
02ba0b45382acb6c0d47bde301e0eb2d7aaacfe8ddfa033188fa02c7b56f0dcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / test_timings-0.2.0-py3-none-any.whl

Download URL test_timings-0.2.0-py3-none-any.whl
Size 22.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b50ba1e0b404ee3b395301ed380e76e47ad8371897d5962c169e12768dc0fdc8
BLAKE2b-256 checksum
How to use checksums
2786baad038b49b932469e39719e8394ac46eaecaeb659eacce2ae5a15947202
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for test-timings 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for test_timings-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page