Use context managers to open the .json files we're about to parse, so
that python doesn't warn about unclosed files.

Signed-off-by: Ross Burton <[email protected]>
---
 meta/classes-recipe/testexport.bbclass  | 3 ++-
 meta/lib/oeqa/sdk/testmetaidesupport.py | 3 ++-
 meta/lib/oeqa/sdk/testsdk.py            | 3 ++-
 meta/lib/oeqa/sdkext/testsdk.py         | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/meta/classes-recipe/testexport.bbclass 
b/meta/classes-recipe/testexport.bbclass
index 344ae489b5a..12b7e171129 100644
--- a/meta/classes-recipe/testexport.bbclass
+++ b/meta/classes-recipe/testexport.bbclass
@@ -52,7 +52,8 @@ def testexport_main(d):
                              d.getVar('IMAGE_LINK_NAME') or 
d.getVar('IMAGE_NAME')))
 
     tdname = "%s.testdata.json" % image_name
-    td = json.load(open(tdname, "r"))
+    with open(tdname, "r") as f:
+        td = json.load(f)
 
     logger = logging.getLogger("BitBake")
 
diff --git a/meta/lib/oeqa/sdk/testmetaidesupport.py 
b/meta/lib/oeqa/sdk/testmetaidesupport.py
index 00ef30e82e9..1110c40b9bf 100644
--- a/meta/lib/oeqa/sdk/testmetaidesupport.py
+++ b/meta/lib/oeqa/sdk/testmetaidesupport.py
@@ -21,7 +21,8 @@ class TestSDK(object):
 
         sdk_envs = 
OESDKTestContextExecutor._get_sdk_environs(d.getVar("DEPLOY_DIR_IMAGE"))
         tdname = d.expand("${DEPLOY_DIR_IMAGE}/${PN}.testdata.json")
-        test_data = json.load(open(tdname, "r"))
+        with open(tdname, "r") as f:
+            test_data = json.load(f)
 
         host_pkg_manifest = {"cmake-native":"", "gcc-cross":"", 
"gettext-native":"", "meson-native":"", "perl-native":"", 
"python3-core-native":"", }
         target_pkg_manifest = {"gtk+3":""}
diff --git a/meta/lib/oeqa/sdk/testsdk.py b/meta/lib/oeqa/sdk/testsdk.py
index cffcf9f49a9..98ef9c71cd6 100644
--- a/meta/lib/oeqa/sdk/testsdk.py
+++ b/meta/lib/oeqa/sdk/testsdk.py
@@ -103,7 +103,8 @@ class TestSDK(TestSDKBase):
             bb.fatal("The toolchain %s is not built. Build it before running 
the tests: 'bitbake <image> -c populate_sdk' ." % tcname)
 
         tdname = 
d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.testdata.json")
-        test_data = json.load(open(tdname, "r"))
+        with open(tdname, "r") as f:
+            test_data = json.load(f)
 
         target_pkg_manifest = self.context_executor_class._load_manifest(
             d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"))
diff --git a/meta/lib/oeqa/sdkext/testsdk.py b/meta/lib/oeqa/sdkext/testsdk.py
index 6dc23065a4a..4d626f3e0c2 100644
--- a/meta/lib/oeqa/sdkext/testsdk.py
+++ b/meta/lib/oeqa/sdkext/testsdk.py
@@ -35,7 +35,8 @@ class TestSDKExt(TestSDKBase):
                     " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname)
 
         tdname = 
d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json")
-        test_data = json.load(open(tdname, "r"))
+        with open(tdname, "r") as f:
+            test_data = json.load(f)
 
         target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
             
d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"))
-- 
2.43.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#227561): 
https://lists.openembedded.org/g/openembedded-core/message/227561
Mute This Topic: https://lists.openembedded.org/mt/116733243/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to