Skip to content

Commit fa45877

Browse files
committed
Set IAM_UNITS_CACHE for each pytest-xdist worker
- Work around hgrecco/flexcache#6 using the environment variable added in iam-units 2025.10.13.
1 parent 12cf19e commit fa45877

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

message_ix/testing/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
# Pytest hooks
2626

2727

28+
def pytest_configure(config: pytest.Config) -> None:
29+
"""Force iam-units to use a distinct cache for each worker.
30+
31+
Work around for https://github.com/hgrecco/flexcache/issues/6 /
32+
https://github.com/IAMconsortium/units/issues/54.
33+
"""
34+
name = f"iam-units-{os.environ.get('PYTEST_XDIST_WORKER', '')}".rstrip("-")
35+
os.environ["IAM_UNITS_CACHE"] = str(config.cache.mkdir(name))
36+
37+
2838
def pytest_report_header(config: pytest.Config, start_path: Path) -> str:
2939
"""Add the message_ix import path to the pytest report header."""
3040
import message_ix

0 commit comments

Comments
 (0)