Skip to content

Runner tests/run.py ​

A wrapper for any check: the full stdout/stderr goes to a log, the terminal gets a short summary. Only the Python standard library.

sh
python3 tests/run.py [--verbose] [--log /path/new.log] -- <command> [arguments...]

What it does ​

  • Runs the command in a new process group and writes its output to a log: by default a new /tmp/ours-check-*.log, with --log — the given file (an existing one is not overwritten, it is opened with xb). --verbose additionally streams the output to the terminal.
  • Prints RUN <command> and the log path, and on completion — PASS/FAIL, the exit code and the time, and the counters parsed from the log:
    • Cargo: the lines test result: … N passed; M failed; K ignored; across all suites;
    • E2E: the lines ok, FAIL, skip (the expect/expect_log markers from tests/e2e/run.sh). If nothing is recognized, it says so (No recognized test summary.) and does not make numbers up.
  • On an error without --verbose — up to 40 lines of diagnostics: up to 10 failed tests and the surroundings of the lines panicked at, error[/error:, FAIL, ERROR:; if there are none — the tail of the log.
  • FAIL if the code is non-zero or there are failed tests: a successful suite does not hide a subsequent build or bench error. The command's exit code is preserved; a signal — 128+N.
  • SIGINT/SIGTERM are forwarded to the whole group of child processes.
  • Sets OURS_TEST_REPORT_ACTIVE=1 in the environment (from it tests/e2e/run.sh knows it is already inside the runner and does not enter it a second time) and CARGO_TERM_COLOR=never by default.
  • After every cargo command (if not interrupted) it prunes <target>/*/build/<pkg>/, keeping the 8 newest hash directories of each package: rebuilt test binaries get a new hash, and the old ones pile up in the shared target/. A profile whose .cargo-lock is held (a build is running) is skipped. OURS_SWEEP=0 turns this off.

Examples ​

sh
python3 tests/run.py -- cargo test -p ours-mod-socks --test socks
python3 tests/run.py -- cargo clippy --workspace --all-targets -- -D warnings
python3 tests/run.py --verbose -- cargo test -p ours-json
python3 tests/run.py -- python3 tests/dashboard/test_admin.py

tests/e2e/run.sh hooks up the runner itself — no need to wrap it.

Rules for new tests ​

  • A successful test is silent; the result is reported by the framework (Cargo, expect in E2E).
  • An error names the expected and the actual value, the case, the parameters, the seed — so as to reproduce it.
  • Large data — by length, the place of divergence or a hash, not in full.
  • A skip — by the framework's means and with a reason (#[ignore = "…"], skip).

Tests of the runner itself ​

tests/test_runner.py — a unittest that runs the runner as a subprocess: logs, summaries, exit codes, interruption; without the network and Docker:

sh
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p test_runner.py

GPL-3.0-or-later