Modify sys.modules in place rather than replacing the dictionary

The lazy imports feature added in Python 3.15 holds a reference to the
original sys.modules, causing issues when the test fixture replaces it
during the test run. The tests, run individually, pass, but in the
sequential run - fail. See:
https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/201#comment-333958
This commit is contained in:
Karolina Surma 2026-08-04 11:43:19 +02:00
commit f7eefdbf58

View file

@ -20,7 +20,8 @@ def preserve_sys_path():
def preserve_sys_modules():
original_sys_modules = dict(sys.modules)
yield
sys.modules = original_sys_modules
sys.modules.clear()
sys.modules.update(original_sys_modules)
@pytest.mark.parametrize(