From ba84b0b3470f6b4ed0a5d70f6401caaa6523d88f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 8 Nov 2022 15:40:12 +0100 Subject: conftest: force loading the facts before the monkeypatch is enabled This provides more freedom to use Pathlib when loading the facts for the projects and inventory. Without this kind of early loading, the monkeypatch can potentially cause the load to fail. Signed-off-by: Paolo Bonzini --- lcitool/targets.py | 4 ++-- tests/test_manifest.py | 3 +++ tests/test_utils/utils.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lcitool/targets.py b/lcitool/targets.py index ef6deab..e796bb1 100644 --- a/lcitool/targets.py +++ b/lcitool/targets.py @@ -28,7 +28,7 @@ class Targets(): @property def target_facts(self): if self._target_facts is None: - self._target_facts = self._load_target_facts() + self._load_target_facts() return self._target_facts @property @@ -79,7 +79,7 @@ class Targets(): # missing per-distro facts fall back to shared facts util.merge_dict(shared_facts, facts[target]) - return facts + self._target_facts = facts class BuildTarget: diff --git a/tests/test_manifest.py b/tests/test_manifest.py index 33ef4e3..c47201c 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -55,6 +55,9 @@ def test_generate(targets, packages, projects, monkeypatch): return filter(lambda f: fnmatch(f.as_posix(), pattern), files) + # Force loading the facts before monkeypatching is enabled + test_utils.force_load(packages=packages, projects=projects, targets=targets) + monkeypatch.setattr(util, 'generate_file_header', fake_header) with monkeypatch.context() as m: diff --git a/tests/test_utils/utils.py b/tests/test_utils/utils.py index 6d097e0..edfb72d 100644 --- a/tests/test_utils/utils.py +++ b/tests/test_utils/utils.py @@ -115,3 +115,14 @@ def assert_matches_file(actual, expected_path, allow_regenerate=True): expected = fd.read() assert_equal(actual, expected, [f"comparing against {expected_path}"]) + + +# Force loading the facts, for example to avoid conflicts with monkeypatching +def force_load(packages=None, projects=None, targets=None): + if packages: + packages._load_mappings() + if projects: + projects._load_public() + projects._load_internal() + if targets: + targets._load_target_facts() -- cgit v1.1