From nobody Mon Apr 6 19:59:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8556E3D88FD; Wed, 18 Mar 2026 14:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773843979; cv=none; b=B7ae5kSJY1MeDPgfA7ARBH18IMM/sEWX+cc3SOEhzXejttnpHX/8DmxTUQNSRPsneIpFb+dgHR0xBSSIG/T7hFJXs4+NJSZtbqqbuyvaAaXeGmZQnWszBICu+5GQ8SHIx4cZVmRSuXrGRQPvs83zuhs3Qdwz48bOqWIUOU8m9aM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773843979; c=relaxed/simple; bh=SbTGzPiBvYBl5sLtu8jLO7RNBFHfCo7Ima/HbCP221M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TefrmmwITlFEq/gTVetnCVIxX263EY2plfxCpof+nZ9JxhLqIJbEu1o4W547MOZHsora7LqoMTGt6qPd8DPUHJRf26yeW/L2HS6ZI5Jin5AN20UosyjRhPLDGHJhMFz23/8dupSnCpudhDNoA7m/eizb18/yyOK8oXh1WK+fDqU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XPGX0dn9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XPGX0dn9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64771C2BCB0; Wed, 18 Mar 2026 14:26:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773843979; bh=SbTGzPiBvYBl5sLtu8jLO7RNBFHfCo7Ima/HbCP221M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XPGX0dn9OpgFU+F9CQAM8o4PC5lLhB+uW7UdwXbRYpdHk/iDSMai5hlAssNGw/6KQ NVhbIhVZSRyRE/7Ak9/bT8+dKioRqLULAf38qNMPwOC1jvCCq+5MbXCjt8PBnY/qwI Zc2K51+VjuoXJQYxRhxqM5IuK1oFfN4lFZ8dITWM1oFWqLe8qSCVLnwpI69viy3AKh 9sTmercMdX58Pumea9PTOzLEWREYign5nf6WaZeDDYeZ7KnWxvFpIB+ZolPXItrEJR pMleKOggjhvEzjQ/CYk2EpPrEH5ciaFoL87LYaIL7L7+lsERJwW2sx7Qo5da8yv3AJ OW7YSzloSYNBA== Received: from mchehab by mail.kernel.org with local (Exim 4.99.1) (envelope-from ) id 1w2rqj-00000004HYT-1vud; Wed, 18 Mar 2026 15:26:17 +0100 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List , Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Subject: [PATCH 2/7] unittests: test_kdoc_parser: add command line arg to read a YAML file Date: Wed, 18 Mar 2026 15:26:06 +0100 Message-ID: <35cc58a54256dc04da237d2991f767262699e353.1773841456.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab The test_kdoc_parser.py already supports loading dynamic tests when running unit tests. Add support to read from a different file. This is useful for: - regression tests before/afer some changes; - preparing new unit tests; - test a different yaml before adding its contents at tools/unittests/kdoc-test.yaml. It should be noticed that passing an argument to a unit test is not too trivial, as unittest core will load itself the runner with a separate environment. The best (only?) way to do it is by setting the system environment. This way, when the class is called by the unit test loader, it can pick the var from the environment without relying on a global variable. The unittest_helper has already provision for it, so let's use its support. Signed-off-by: Mauro Carvalho Chehab --- tools/unittests/test_kdoc_parser.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/unittests/test_kdoc_parser.py b/tools/unittests/test_kdo= c_parser.py index 723dd8c7f4f3..f2250ef192ce 100755 --- a/tools/unittests/test_kdoc_parser.py +++ b/tools/unittests/test_kdoc_parser.py @@ -30,7 +30,7 @@ from kdoc.kdoc_output import RestFormat, ManFormat =20 from kdoc.xforms_lists import CTransforms =20 -from unittest_helper import run_unittest +from unittest_helper import TestUnits =20 =20 # @@ -38,6 +38,10 @@ from unittest_helper import run_unittest # TEST_FILE =3D os.path.join(SRC_DIR, "kdoc-test.yaml") =20 +env =3D { + "yaml_file": TEST_FILE +} + # # Ancillary logic to clean whitespaces # @@ -470,7 +474,9 @@ class KernelDocDynamicTests(): optional ones. """ =20 - with open(TEST_FILE, encoding=3D"utf-8") as fp: + test_file =3D os.environ.get("yaml_file", TEST_FILE) + + with open(test_file, encoding=3D"utf-8") as fp: testset =3D yaml.safe_load(fp) =20 tests =3D testset["tests"] @@ -531,4 +537,15 @@ KernelDocDynamicTests.create_tests() # Run all tests # if __name__ =3D=3D "__main__": - run_unittest(__file__) + runner =3D TestUnits() + parser =3D runner.parse_args() + parser.add_argument("-y", "--yaml-file", "--yaml", + help=3D'Name of the yaml file to load') + + args =3D parser.parse_args() + + if args.yaml_file: + env["yaml_file"] =3D os.path.expanduser(args.yaml_file) + + # Run tests with customized arguments + runner.run(__file__, parser=3Dparser, args=3Dargs, env=3Denv) --=20 2.52.0