From fe2fcf60349d6450c0e558d5dc9de04a68ca76ae Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 21 Oct 2026 10:01:23 +0200 Subject: [PATCH] fix: create tmp/tests when the test package loads Most modules write under tmp/, which a fresh clone lacks, and only three created it on import. A module run alone failed with FileNotFoundError on a temporary directory. --- tests/__init__.py | 9 +++++++++ tests/test_audit_regressions.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/__init__.py b/tests/__init__.py index e18270d4..0190e539 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,10 +4,19 @@ The CI job sets RETROBIOS_OFFLINE, but a local run of the documented command did not, and e2e fixtures queried the large-files release and wrote its answers into the shared .cache/large. A test that serves its own assets clears the variable for itself. + +Scratch files go under the repository's tmp/, which git does not track: a +fresh clone has none, and a module run alone raised FileNotFoundError on a +temporary directory instead of naming the missing parent. """ from __future__ import annotations import os +from pathlib import Path os.environ.setdefault("RETROBIOS_OFFLINE", "1") + +(Path(__file__).resolve().parent.parent / "tmp" / "tests").mkdir( + parents=True, exist_ok=True +) diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 6e8e98e2..2a8c43a3 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -166,6 +166,27 @@ class ReadmeRegressions(unittest.TestCase): self.assertEqual(failed, {}) +class AModuleRunAloneHasItsScratchDirectory(unittest.TestCase): + """About forty modules write under tmp/, which git does not track. Only + three created it, as an import side effect, so a module run alone on a + fresh clone raised FileNotFoundError. The test package creates it.""" + + def test_importing_the_package_creates_tmp(self): + with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: + clone = Path(directory) + (clone / "tests").mkdir() + (clone / "tests" / "__init__.py").write_bytes( + (ROOT / "tests" / "__init__.py").read_bytes() + ) + proc = subprocess.run( + [sys.executable, "-I", "-c", + "import sys; sys.path.insert(0, '.'); import tests"], + cwd=clone, capture_output=True, text=True, timeout=60, check=False, + ) + self.assertEqual(proc.returncode, 0, proc.stderr) + self.assertTrue((clone / "tmp" / "tests").is_dir()) + + class ReleaseSigningRegressions(unittest.TestCase): """A checksum list published beside its own artifacts proves nothing.