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.
This commit is contained in:
Bruno Postle
2026-04-10 00:30:26 +01:00
parent aa3e38aca8
commit 9bcc98aac3
2 changed files with 24 additions and 9 deletions
+1 -1
View File
@@ -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
@@ -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():