From e96baf588dfa90d366e94f2a72ec8941e397c596 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Thu, 11 Dec 2025 17:59:06 +0000 Subject: [PATCH] oeqa: open JSON to parse in a context manager 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 Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- 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 344ae489b5..12b7e17112 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 00ef30e82e..1110c40b9b 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 cffcf9f49a..98ef9c71cd 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 -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 6dc23065a4..4d626f3e0c 100644 --- a/meta/lib/oeqa/sdkext/testsdk.py +++ b/meta/lib/oeqa/sdkext/testsdk.py @@ -35,7 +35,8 @@ class TestSDKExt(TestSDKBase): " tests: 'bitbake -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.47.3