From 528774b256700b0e00296d4321581f856d86ce99 Mon Sep 17 00:00:00 2001 From: Adrian Blumer Date: Wed, 18 Nov 2026 16:00:50 -0800 Subject: [PATCH 1/2] test: delete the tmp_path of each passing test A full test run leaves about 6.4 GB of temporary files. pytest now deletes the tmp_path of a test that passed when the test ends (tmp_path_retention_policy = "failed"). pytest then gives the deleted folder's name to the next test with the same name prefix. Some tests leave a reader open, and DuckDB keeps one database per file path while a connection is open, so the next test read the earlier test's control.duckdb. A tmp_path fixture in the root conftest.py now gives each test its own subfolder with a random name. The CI pytest steps also pass --durations=25, so each log lists the slowest tests. --- .github/workflows/pre-commit-hooks.yaml | 9 +++++++++ conftest.py | 18 ++++++++++++++++++ pyproject.toml | 2 ++ 3 files changed, 29 insertions(+) diff --git a/.github/workflows/pre-commit-hooks.yaml b/.github/workflows/pre-commit-hooks.yaml index 5e8fb5789..a618588f5 100644 --- a/.github/workflows/pre-commit-hooks.yaml +++ b/.github/workflows/pre-commit-hooks.yaml @@ -50,6 +50,9 @@ 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 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 +79,9 @@ 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 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 +119,9 @@ 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 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. From 177f37292c40f84f514daf67aafa304c03a7ae56 Mon Sep 17 00:00:00 2001 From: Adrian Blumer Date: Wed, 18 Nov 2026 16:00:51 -0800 Subject: [PATCH 2/2] ci: keep pytest's temporary files in memory The three CI pytest steps set TMPDIR=/dev/shm, so pytest writes its temporary files to memory instead of the runner's disk. --- .github/workflows/pre-commit-hooks.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pre-commit-hooks.yaml b/.github/workflows/pre-commit-hooks.yaml index a618588f5..7966d71d0 100644 --- a/.github/workflows/pre-commit-hooks.yaml +++ b/.github/workflows/pre-commit-hooks.yaml @@ -53,6 +53,8 @@ jobs: 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. @@ -82,6 +84,8 @@ jobs: 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 @@ -122,6 +126,8 @@ jobs: 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