From 558aac640887e832bdff964ae2c70c718449b54a Mon Sep 17 00:00:00 2001 From: Petros Aristidou Date: Fri, 20 Nov 2026 13:33:38 +0200 Subject: [PATCH] Fake-engine tests no longer load the RAMSES library The STOP-check tests built a real stepss.sim() and swapped its library for a fake, so each held a reference to the RAMSES DLL for as long as the object lived. A test that raises keeps the object alive through the exception's traceback until the garbage collector runs. On Windows the DLL is only unloaded, and its Fortran state reset, when the last reference goes, and test_ssa_engine.py relies on that reset between fixtures: on master after the merge, windows-latest with Python 3.12 found the previous test's simulation still at t = 0.5 s, while the other five legs passed, and the same leg passed in the v3.85 release gate. A late collection is the likely cause. FakeSim subclasses sim without calling its __init__ and unloads nothing, so these tests cannot hold the library at all. --- tests/test_divergence.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/test_divergence.py b/tests/test_divergence.py index d6991dc..ed5fcc0 100644 --- a/tests/test_divergence.py +++ b/tests/test_divergence.py @@ -32,6 +32,8 @@ import pytest +import stepss + REPO_ROOT = Path(__file__).resolve().parents[1] CASE_DIR = REPO_ROOT / "tests" / "data" / "nordic" @@ -204,12 +206,32 @@ def faked(tmp_path, engine): case.addData(str(tmp_path / "d.dat")) case.addDst(str(tmp_path / "c.dst")) case.addOut(str(tmp_path / "output.trace")) - ram = stepss.sim() - # sim.__del__ unloads the library through this handle, so the fake - # carries the real one and the real library is still released once. - engine._handle = ram._ramseslib._handle - ram._ramseslib = engine - return ram, case + return FakeSim(engine), case + + +class FakeSim(stepss.sim): + """A sim that never loads the real library. + + It used to be a real stepss.sim() with its library swapped out, which + held a reference to the RAMSES DLL for as long as the object lived. A + test that raises keeps the object alive through the exception's + traceback until the garbage collector gets to it, and on Windows the + DLL is only unloaded, and its Fortran state reset, when the last + reference goes. test_ssa_engine.py relies on that reset between + fixtures, and on windows-latest with Python 3.12 it once found the + previous test's simulation still at t = 0.5 s, the other five legs + passing. A late collection of such an object is the likely cause, + which is also why it is intermittent; a fake that never loads the + library cannot cause it either way. + """ + + def __init__(self, engine): # deliberately not calling sim.__init__ + self._ramseslib = engine + self._stopTime = None + self._traceFile = None + + def __del__(self): # nothing loaded, nothing to unload + pass def test_an_unflagged_early_end_raises_with_the_engine_line(tmp_path):