From 9bcc98aac3372e3eebb0299e247697b15adbb9fd Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Fri, 10 Apr 2026 00:30:26 +0100 Subject: [PATCH] tests: fix test_memusage_partial_open and add psutil to CI Run the RSS measurement in a subprocess so the fixture file is not already in the page cache from earlier tests (which made both deltas read as zero). Add psutil to the CI pip install so this test is not skipped there. 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 95f3c196ac..06b6481ede 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 + pip install xmlschema xsdata numpy lxml pytest isodate lark networkx tabulate python-dateutil shapely 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():