diff --git a/.github/workflows/pre-commit-hooks.yaml b/.github/workflows/pre-commit-hooks.yaml index 5e8fb5789..7966d71d0 100644 --- a/.github/workflows/pre-commit-hooks.yaml +++ b/.github/workflows/pre-commit-hooks.yaml @@ -50,6 +50,11 @@ jobs: - name: Unit tests id: unit continue-on-error: true + env: + # Lists the slowest tests at the end of the log. + PYTEST_ADDOPTS: --durations=25 + # Keeps pytest's temporary files in memory instead of on the runner's disk. + TMPDIR: /dev/shm run: make test-unit # Both steps above run to completion even when one fails, so the report lists every outcome # instead of stopping at the first. @@ -76,6 +81,11 @@ jobs: - name: Test with pytest (Python 3.13) id: pytest continue-on-error: true + env: + # Lists the slowest tests at the end of the log. + PYTEST_ADDOPTS: --durations=25 + # Keeps pytest's temporary files in memory instead of on the runner's disk. + TMPDIR: /dev/shm run: make test - name: Test connectors in per-connector environments # Each connector's tests and type-check run in an environment built from its own @@ -113,6 +123,11 @@ jobs: - name: Install dependencies run: make sync - name: Test with pytest (Python 3.11) + env: + # Lists the slowest tests at the end of the log. + PYTEST_ADDOPTS: --durations=25 + # Keeps pytest's temporary files in memory instead of on the runner's disk. + TMPDIR: /dev/shm run: make test # The ruleset on main requires one status check context named exactly `check`, and a check run diff --git a/conftest.py b/conftest.py index 6802ea210..9c7457fa3 100644 --- a/conftest.py +++ b/conftest.py @@ -1,6 +1,8 @@ """Give each test an empty TimeNet store, registry and cache.""" import os +from pathlib import Path +import uuid import pytest @@ -20,3 +22,19 @@ def _timenet_state(tmp_path_factory, monkeypatch): monkeypatch.setenv("TIMENET_LOCAL_REGISTRY", str(root / "store")) monkeypatch.setenv("TIMENET_REMOTE_REGISTRY", str(root / "remote")) monkeypatch.setenv("TIMENET_CACHE", str(root / "cache")) + + +@pytest.fixture +def tmp_path(tmp_path: Path) -> Path: + """Give each test a folder that no other test of the run uses. + + pytest deletes the folder of a passing test (``tmp_path_retention_policy``) and then gives its + name to the next test with the same name prefix. A file that the earlier test left open would + then be found at the later test's path. + + Returns: + An empty folder inside pytest's own ``tmp_path``, which pytest deletes after the test. + """ + path = tmp_path / uuid.uuid4().hex[:8] + path.mkdir() + return path diff --git a/pyproject.toml b/pyproject.toml index 1b9ddbfe8..7b19e4924 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -151,6 +151,8 @@ markers = [ "value_dtypes: scalar value-dtype round-trip tests (run with '-m value_dtypes')", "real_provenance: read the real commit of every install type instead of the stub in packages/conftest.py", ] +# Remove the tmp_path folder of a test that passed when the test ends. A full run writes about 7.5 GB. +tmp_path_retention_policy = "failed" [tool.ty.src] # Local git worktrees carry their own (possibly unrelated) copies of the code.