Skip to content
Lars Falk-Petersen edited this page Mar 26, 2025 · 21 revisions

Overview

We run tests via Tox. Tox will set up a separate environment for each test in .tox. This directory can be deleted, as tox will reinstall it on-demand.

Installation

Python 3.10-3.12 tested.

From toml file:

$ pip install ".[tests]"

Manually in your virtual environment:

$ pip install tox

List available tests

$ tox list
default environments:
py310            -> Run pytest, coverage.
py311            -> Run pytest, coverage.
py312            -> Run pytest, coverage.
bandit           -> "Check for security issues. Ignoring asserts for now."
ruff_reformat    -> "Reformat code with ruff format, a Python formatter like black."
ruff_check       -> "Run ruff check, a Python linter. Auto-fix only isort, see pyproject.toml."
trainingdata     -> "Download synthetic data for use in other tests. Will download 80 MB from github. Result end up in .tox/bris_random_data.zarr"
inference_CI     -> "Run inference using checkpoint from tests. Only for CI testing."

additional environments:
prospector       -> "Run static analysis using prospector, don't fail on errors"
ruff_checkformat -> "Run ruff format and complain on changes"
mypy             -> "Check typing with mypy. Only warn, don't fail on errors."
training         -> "Run a test training on synthetic data. Slow! Will take about 5 minutes. Result end up in .tox/training/tmp/training-output"
inference        -> "Run inference on data from training. Requires 'tox -e training' to have run successfully. Result end up in .tox/inference/tmp/. No usable data is generated."

Disk usage

Only some of the tests need a full installation:

$ du -hsc .tox/*
41M	.tox/bandit
88M	.tox/bris_random_data.zarr
6,5G	.tox/inference
80M	.tox/main.zip
63M	.tox/mypy
6,7G	.tox/prospector
12K	.tox/py310
12K	.tox/py311
6,6G	.tox/py312
41M	.tox/ruff_check
41M	.tox/ruff_reformat
6,8G	.tox/training
265M	.tox/trainingdata

Run default tests

$ tox
py310: skipped because could not find python interpreter with spec(s): py310
py310: SKIP ⚠ in 0.02 seconds
py311: skipped because could not find python interpreter with spec(s): py311
py311: SKIP ⚠ in 0.01 seconds
.pkg: _optional_hooks> python /home/larsfp/src/bris-inference/venv/lib/python3.12/site-packages/pyproject_api/_backe
...
All checks passed!
  py310: SKIP (0.02 seconds)
  py311: SKIP (0.01 seconds)
  py312: OK (11.17=setup[2.83]+cmd[8.18,0.16] seconds)
  bandit: OK (0.34=setup[0.01]+cmd[0.33] seconds)
  ruff_reformat: OK (0.05=setup[0.01]+cmd[0.04] seconds)
  ruff_check: OK (0.05=setup[0.01]+cmd[0.05] seconds)
  congratulations :) (11.69 seconds)

Details for each test

Unit tests

py310
py311
py312

pytest will run unit tests in all python versions between 3.10 and 3.12 that are available on the system. Our CI use 3.10.

Security

bandit will check for known security issues in the code (not in libraries), like writing files to a shared temporary directory.

Formatting

Formatting is checked with The Ruff Formatter.

CI will run ruff_checkformat which only reports if formatting is needed. You will have to run the actual formatting using tox -e ruff_reformat, and then commit it.

Lint

Linting is done with The Ruff Linter. isort-changes will be auto-fixed, other errors will be reported. Must run without errors reported before pushing.

tox -e ruff_check

Typing

Type checking with mypy is still a work in process.

Prospector

Other code issues with prospector is still a work in process.

Trainingdata

Will download an 80 MB dataset from github.

Requires wget unzip.

Training

Depends on trainingdata.

Run a test training on synthetic data. Slow! Will take about 5 minutes. Result end up in .tox/training/tmp/training-output

Inference

Depends on trainingdata and training to have run successfully.

Run a test inference. Result end up in .tox/inference/tmp/. No usable data is generated.

Clone this wiki locally