[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b0cd95fc4bf2ea93136503f79e657994eaa51ff6.1770128540.git.mchehab+huawei@kernel.org>
Date: Tue, 3 Feb 2026 15:55:43 +0100
From: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
To: Jonathan Corbet <corbet@....net>,
Linux Doc Mailing List <linux-doc@...r.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>,
linux-kernel@...r.kernel.org,
Jani Nikula <jani.nikula@...ux.intel.com>,
Mauro Carvalho Chehab <mchehab@...nel.org>
Subject: [PATCH 15/15] unittests: test_kdoc_parser: add command line arg to read a YAML file
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 <mchehab+huawei@...nel.org>
---
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_kdoc_parser.py
index dd3d576e1b93..eb2225529325 100755
--- a/tools/unittests/test_kdoc_parser.py
+++ b/tools/unittests/test_kdoc_parser.py
@@ -29,7 +29,7 @@ from kdoc.kdoc_output import RestFormat, ManFormat
from kdoc.xforms_lists import CTransforms
-from unittest_helper import run_unittest
+from unittest_helper import TestUnits
#
@@ -37,6 +37,10 @@ from unittest_helper import run_unittest
#
TEST_FILE = os.path.join(SRC_DIR, "kdoc-test.yaml")
+env = {
+ "yaml_file": TEST_FILE
+}
+
#
# Ancillary logic to clean whitespaces
#
@@ -442,7 +446,9 @@ class KernelDocDynamicTests():
optional ones.
"""
- with open(TEST_FILE, encoding="utf-8") as fp:
+ test_file = os.environ.get("yaml_file", TEST_FILE)
+
+ with open(test_file, encoding="utf-8") as fp:
testset = yaml.safe_load(fp)
tests = testset["tests"]
@@ -503,4 +509,15 @@ KernelDocDynamicTests.create_tests()
# Run all tests
#
if __name__ == "__main__":
- run_unittest(__file__)
+ runner = TestUnits()
+ parser = runner.parse_args()
+ parser.add_argument("-y", "--yaml-file", "--yaml",
+ help='Name of the yaml file to load')
+
+ args = parser.parse_args()
+
+ if args.yaml_file:
+ env["yaml_file"] = os.path.expanduser(args.yaml_file)
+
+ # Run tests with customized arguments
+ runner.run(__file__, parser=parser, args=args, env=env)
--
2.52.0
Powered by blists - more mailing lists