From ee5d67249345f1f7873e38623cace3a51ddc0c8c Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Sat, 4 Jul 2026 17:32:44 +0100 Subject: [PATCH] tests: fix test_memusage_partial_open and add psutil to CI test_memusage_partial_open was silently skipped in CI (psutil was never installed there). Add psutil so it actually runs, and run the RSS measurement in a subprocess so the fixture file isn't already in the page cache from earlier tests, which was making both deltas read as zero. Generated with the assistance of an AI coding tool. --- .github/workflows/ci.yml | 2 +- ...st_streaming_rocksdb_and_simpletyperefs.py | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83bdfc9825..255ce63308 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install xmlschema xsdata numpy lxml pytest isodate lark networkx tabulate python-dateutil shapely pyparsing + pip install xmlschema xsdata numpy lxml pytest isodate lark networkx tabulate python-dateutil shapely pyparsing psutil pip install src/bcf --no-deps pip install pytest-xdist==3.8.0 diff --git a/src/ifcopenshell-python/test/test_streaming_rocksdb_and_simpletyperefs.py b/src/ifcopenshell-python/test/test_streaming_rocksdb_and_simpletyperefs.py index 32ea728df9..bd93378a22 100644 --- a/src/ifcopenshell-python/test/test_streaming_rocksdb_and_simpletyperefs.py +++ b/src/ifcopenshell-python/test/test_streaming_rocksdb_and_simpletyperefs.py @@ -74,14 +74,29 @@ def test_opening_unicode(): @pytest.mark.skipif(psutil is None, reason="psutil not installed") def test_memusage_partial_open(): - m0 = psutil.Process().memory_info().rss - f = ifcopenshell.open(fn) - m1 = psutil.Process().memory_info().rss - g = ifcopenshell.open(fn, bypass_types=("IfcRepresentationItem",)) - m2 = psutil.Process().memory_info().rss - # arbitrary... - expected_ratio = 0.75 - assert (m2 - m1) < (m1 - m0) * expected_ratio + # Run in a subprocess to ensure the file is not already in the process page + # cache from earlier tests, which would make both RSS deltas read as zero. + import subprocess + import sys + + script = f""" +import psutil +import ifcopenshell + +fn = {repr(fn)} +m0 = psutil.Process().memory_info().rss +f = ifcopenshell.open(fn) +m1 = psutil.Process().memory_info().rss +g = ifcopenshell.open(fn, bypass_types=("IfcRepresentationItem",)) +m2 = psutil.Process().memory_info().rss +expected_ratio = 0.75 +assert (m2 - m1) < (m1 - m0) * expected_ratio, ( + f"bypass_types did not reduce memory: normal open added {{m1 - m0}} bytes, " + f"bypass open added {{m2 - m1}} bytes (expected < {{(m1 - m0) * expected_ratio:.0f}})" +) +""" + result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True) + assert result.returncode == 0, result.stderr or result.stdout def test_rocks():