From patchwork Mon Mar 16 15:47:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1994 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676114; bh=1FL1+vZj4OH++HxmPpcNIu/K303HMsJZbdRHzds0Gj0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=nm39hmtMx24+QgMp4GYE2Vy3C06TgOtG7dJDeM2Z/0y/BAx2bULltoWQQEwLX05P9 6aAa0l+6+DITbG932OFkiRQl0Pqp8J/Y88aWEiqUusFEZP1H0j+W29Y/wIs7kzhJ2M ErXxxaAta3xjMJl5CRhkUfc1A7fd9VP26vPNGt3QJKmJNT58ayYR//w0Ha7LEpnqK/ SzDwFNdX4OOlYFMFE5HEcnzRtGCPwDNfRNJD86e1cUzfwir8HdzKwzMIoXsA0CIv9A 9Zs1cTIs36+t3oAqswyMApPElOVpuVzdvip6t4n8o/AyuTQSCRVr6VReCBkETGGuZp X6dzn769Bdn5Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6EDFE6A061 for ; Mon, 16 Mar 2026 09:48:34 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Ld0b853cmk8t for ; Mon, 16 Mar 2026 09:48:34 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676113; bh=1FL1+vZj4OH++HxmPpcNIu/K303HMsJZbdRHzds0Gj0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=PXYI6kJRdDTSX8IGNnayzSarllhqKf7mra+j0/rHg5daqfVkoDnT4rtnYQBi+5jRp dT69BaUM1GeXzz/gp8HrLmmUZK1/uMXiSj6SfW3oGodP5+Ji1fZnyCVDaRlpZRv1G8 UyOaRy26b9ZFfrYnaI/92Rl1W3vw3s1duZTdkzjr/vsyh9+xtUrGUeBBC+lwnAgYR2 Wo9qv8s0LMHndpAWbZuzwjz/dTD1mKpHZ8dd+p/R8WOKI71GeVd7I8LSk3zTggiuos H1idDJPRib5nBpNh3xINN2hxwPlidsn2zMI0SAGFqxQ5+l6JVRzKvJflcYS+q9tSVR M52wSVhH6DxIQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5D4126A07C for ; Mon, 16 Mar 2026 09:48:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676111; bh=PMDzbxA8CwTmY7v8cfc3C12jxBXK83O0Jo/4wz0Gy0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nDBc6qjlE0Yq8Fn2iLbNTMmzlxjKJhn2d5PFhq4JeapnoHBBe10E273rn6tjNIv5Q BPsC3lnSaZNDcc8QQraNijGet7tXBcWCqwEwuNDCxL+PA0OltZVZwuXPLhd0bnFPsw MDnRoMiRc/0tx8KLZfH6PB0B08aI/vuWY/zrOgeMp7wBYoiTdx79rpbfk9loQGU+ED yb3T0mlkJIB1y002GzzWl3Po3fH8YIDKt3mlidVHDVbURDlhlIgGRytBtnBBSspbyn mSaU61uSSuRBYK9ZKM8rm+2/DtDH8UqYxWgg0pyM8+e2dWIw/uhMNwjepT1EIhe4U9 xv/P3WHl6cKUA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7CCEA6A07C; Mon, 16 Mar 2026 09:48:31 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id HWu8w8mIEYYG; Mon, 16 Mar 2026 09:48:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773676111; bh=4Bs1S+X1O0CZIKxsxhLJN/BDa7fcByVeoeBZBRjGTf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qGGPB6pvzhvhWcSYsYT1fPU/Ro61AX87CnfSybc4fC1bgISC6OsVrMx1sIGpL2eR5 fN5ybVm93pzj2Ur6fbAyaKe7KdHKy8bZI20w0KU93rRDy2lLX0MECaOltqtLsJfG4G UJ32Hmv6+0TdlF36clm5jZejouyU182p6PvQJ4H4JEtOvPMeriGHwuzSsihYqYylVA Fp8ikwfWG8yjhWCRmtVJs0BN0B/90GkoeWRnlhjA+tNZ53pev+GTA2NjsRiV4Ek0nJ DwD21/CSfLVM9WDtEUAG5cmsUPIEzNSoFYZiiFnrhLW9871bmtiCE8GkRXbLse2Lsm 68HfEcwrSs1uA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id EA2336A061; Mon, 16 Mar 2026 09:48:30 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 09:47:07 -0600 Message-ID: <20260316154733.1587261-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316154733.1587261-1-sjg@u-boot.org> References: <20260316154733.1587261-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: VREW4D56KKCPMFAJP2ILDOZQ2OCLNC2J X-Message-ID-Hash: VREW4D56KKCPMFAJP2ILDOZQ2OCLNC2J X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/20] u_boot_pylib: Support passing modules to run_test_suites() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Allow passing a module object to run_test_suites() in addition to test classes and doctest module name strings. When a module is passed, all TestCase subclasses are extracted automatically. This avoids having to enumerate every test class when registering a test module. Signed-off-by: Simon Glass --- tools/u_boot_pylib/test_util.py | 49 ++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/tools/u_boot_pylib/test_util.py b/tools/u_boot_pylib/test_util.py index b1c8740d883..90ae0cee6ce 100644 --- a/tools/u_boot_pylib/test_util.py +++ b/tools/u_boot_pylib/test_util.py @@ -203,24 +203,41 @@ def run_test_suites(toolname, debug, verbosity, no_capture, test_preserve_dirs, if isinstance(module, str) and (not test_name or test_name == module): suite.addTests(doctest.DocTestSuite(module)) - for module in class_and_module_list: - if isinstance(module, str): + for entry in class_and_module_list: + if isinstance(entry, str): continue - # Test the test module about our arguments, if it is interested - if hasattr(module, 'setup_test_args'): - setup_test_args = getattr(module, 'setup_test_args') - setup_test_args(preserve_indir=test_preserve_dirs, - preserve_outdirs=test_preserve_dirs and test_name is not None, - toolpath=toolpath, verbosity=verbosity, no_capture=no_capture) - if test_name: - # Since Python v3.5 If an ImportError or AttributeError occurs - # while traversing a name then a synthetic test that raises that - # error when run will be returned. Check that the requested test - # exists, otherwise these errors are included in the results. - if test_name in loader.getTestCaseNames(module): - suite.addTests(loader.loadTestsFromName(test_name, module)) + + # If entry is a module, extract all TestCase subclasses from it + if hasattr(entry, '__file__'): + classes = [obj for obj in vars(entry).values() + if (isinstance(obj, type) + and issubclass(obj, unittest.TestCase) + and obj is not unittest.TestCase)] else: - suite.addTests(loader.loadTestsFromTestCase(module)) + classes = [entry] + + for module in classes: + # Tell the test module about our arguments, if interested + if hasattr(module, 'setup_test_args'): + setup_test_args = getattr(module, 'setup_test_args') + setup_test_args( + preserve_indir=test_preserve_dirs, + preserve_outdirs=(test_preserve_dirs + and test_name is not None), + toolpath=toolpath, verbosity=verbosity, + no_capture=no_capture) + if test_name: + # Since Python v3.5 If an ImportError or + # AttributeError occurs while traversing a name then + # a synthetic test that raises that error when run + # will be returned. Check that the requested test + # exists, otherwise these errors are included in the + # results. + if test_name in loader.getTestCaseNames(module): + suite.addTests( + loader.loadTestsFromName(test_name, module)) + else: + suite.addTests(loader.loadTestsFromTestCase(module)) print(f" Running {toolname} tests ".center(70, "=")) result = runner.run(suite)