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():