diff mbox series

[6/6] patchtest: tests: test_metadata.py: parse each recipe only once

Message ID 20261204174107.1295971-7-tgamblin@baylibre.com
State New
Headers show
Series patchtest: script fixes, improve recipe parsing | expand

Commit Message

Trevor Gamblin Dec. 4, 2026, 5:41 p.m. UTC
Each metadata test called tinfoil.parse_recipe() for every recipe it
checked, so after merging, an added recipe was parsed three times and a
modified one twice. The tests only read variables, so parse each recipe
once per test run and reuse the result. Results aren't kept between the
pre-merge and post-merge runs, since the recipes change in between.
test_license_presence's auto.conf change doesn't affect this, since it
happens after bitbake has read its configuration.

AI-Generated: Uses Claude Code Opus 5.5
---
 meta/lib/patchtest/tests/base.py          |  8 ++++++++
 meta/lib/patchtest/tests/test_metadata.py | 10 +++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/patchtest/tests/base.py b/meta/lib/patchtest/tests/base.py
index 3fb9882cb4..e55dd59393 100644
--- a/meta/lib/patchtest/tests/base.py
+++ b/meta/lib/patchtest/tests/base.py
@@ -132,6 +132,7 @@  class Metadata(Base):
     @classmethod
     def setUpClassLocal(cls):
         cls.tinfoil = cls.setup_tinfoil()
+        cls.recipe_data = {}
 
         # get info about added/modified/remove recipes
         cls.added, cls.modified, cls.removed = cls.get_metadata_stats(cls.patchset)
@@ -140,6 +141,13 @@  class Metadata(Base):
     def tearDownClassLocal(cls):
         cls.tinfoil.shutdown()
 
+    @classmethod
+    def parse_recipe(cls, pn):
+        """Parse a recipe, reusing the result for every test that needs it"""
+        if pn not in cls.recipe_data:
+            cls.recipe_data[pn] = cls.tinfoil.parse_recipe(pn)
+        return cls.recipe_data[pn]
+
     @classmethod
     def setup_tinfoil(cls, config_only=False):
         """Initialize tinfoil api from bitbake"""
diff --git a/meta/lib/patchtest/tests/test_metadata.py b/meta/lib/patchtest/tests/test_metadata.py
index 442e80973d..cf02af5528 100644
--- a/meta/lib/patchtest/tests/test_metadata.py
+++ b/meta/lib/patchtest/tests/test_metadata.py
@@ -32,7 +32,7 @@  class TestMetadata(base.Metadata):
 
         no_license = False
         for pn in self.added:
-            rd = self.tinfoil.parse_recipe(pn)
+            rd = self.parse_recipe(pn)
             license = rd.getVar(patchtest_patterns.metadata_lic)
             if license == patchtest_patterns.invalid_license:
                 no_license = True
@@ -56,7 +56,7 @@  class TestMetadata(base.Metadata):
             self.skip('No added recipes, skipping test')
 
         for pn in self.added:
-            rd = self.tinfoil.parse_recipe(pn)
+            rd = self.parse_recipe(pn)
             pathname = rd.getVar('FILE')
             # we are not interested in images
             if '/images/' in pathname:
@@ -111,7 +111,7 @@  class TestMetadata(base.Metadata):
         for pn in self.modified:
             if 'core-image' in pn:
                 continue
-            rd = self.tinfoil.parse_recipe(pn)
+            rd = self.parse_recipe(pn)
             PatchTestDataStore[
                 "%s-%s-%s" % (key_prefix, patchtest_patterns.metadata_src_uri, pn)
             ] = rd.getVar(patchtest_patterns.metadata_src_uri)
@@ -168,7 +168,7 @@  class TestMetadata(base.Metadata):
             # we are not interested in images
             if 'core-image' in pn:
                 continue
-            rd = self.tinfoil.parse_recipe(pn)
+            rd = self.parse_recipe(pn)
             summary = rd.getVar(patchtest_patterns.metadata_summary)
 
             # "${PN} version ${PN}-${PR}" is the default, so fail if default
@@ -190,7 +190,7 @@  class TestMetadata(base.Metadata):
             # we are not interested in images
             if 'core-image' in pn:
                 continue
-            rd = self.tinfoil.parse_recipe(pn)
+            rd = self.parse_recipe(pn)
             cve_check_ignore = rd.getVar(patchtest_patterns.cve_check_ignore_var)
 
             if cve_check_ignore is not None: