aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2022-11-08 15:40:12 +0100
committerErik Skultety <eskultet@redhat.com>2023-01-17 07:30:56 +0000
commitba84b0b3470f6b4ed0a5d70f6401caaa6523d88f (patch)
tree3f763acca716ab37135d29291c67ef1956e3df41
parent6cbf46649a216b92358aa7e141762c55c77337a8 (diff)
downloadlibvirt-ci-ba84b0b3470f6b4ed0a5d70f6401caaa6523d88f.zip
libvirt-ci-ba84b0b3470f6b4ed0a5d70f6401caaa6523d88f.tar.gz
libvirt-ci-ba84b0b3470f6b4ed0a5d70f6401caaa6523d88f.tar.bz2
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 <pbonzini@redhat.com>
-rw-r--r--lcitool/targets.py4
-rw-r--r--tests/test_manifest.py3
-rw-r--r--tests/test_utils/utils.py11
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()