From 4bcdedb0089f2a4544fb0a707774f8e379e3b989 Mon Sep 17 00:00:00 2001 From: aad1tyaaaaa Date: Wed, 2 Dec 2026 23:39:30 +0530 Subject: [PATCH] Treat empty Controllers and TestParams sections in the config as empty dicts --- mobly/config_parser.py | 9 +++++---- tests/mobly/config_parser_test.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/mobly/config_parser.py b/mobly/config_parser.py index 72f3883e2..4aa3187ad 100644 --- a/mobly/config_parser.py +++ b/mobly/config_parser.py @@ -133,11 +133,12 @@ def load_test_config_file(test_config_path, tb_filters=None): # Deprecated, use testbed_name test_run_config.test_bed_name = test_run_config.testbed_name test_run_config.log_path = log_path - test_run_config.controller_configs = original_bed_config.get( - keys.Config.key_testbed_controllers.value, {} + # An empty section in YAML (e.g. a bare `TestParams:`) loads as None. + test_run_config.controller_configs = ( + original_bed_config.get(keys.Config.key_testbed_controllers.value) or {} ) - test_run_config.user_params = original_bed_config.get( - keys.Config.key_testbed_test_params.value, {} + test_run_config.user_params = ( + original_bed_config.get(keys.Config.key_testbed_test_params.value) or {} ) test_configs.append(test_run_config) return test_configs diff --git a/tests/mobly/config_parser_test.py b/tests/mobly/config_parser_test.py index 46548f0f2..327e531f9 100644 --- a/tests/mobly/config_parser_test.py +++ b/tests/mobly/config_parser_test.py @@ -56,6 +56,18 @@ def test__load_config_file_with_unicode(self): config = config_parser._load_config_file(tmp_file_path) self.assertEqual(config['TestBeds'][0]['Name'], '\u901a') + def test_load_test_config_file_with_empty_sections(self): + tmp_file_path = os.path.join(self.tmp_dir, 'config.yml') + with io.open(tmp_file_path, 'w', encoding='utf-8') as f: + f.write('TestBeds:\n') + f.write(' - Name: SampleTestBed\n') + f.write(' Controllers:\n') + f.write(' TestParams:\n') + + config = config_parser.load_test_config_file(tmp_file_path)[0] + self.assertEqual(config.controller_configs, {}) + self.assertEqual(config.user_params, {}) + def test_run_config_type(self): config = config_parser.TestRunConfig() self.assertNotIn('summary_writer', str(config))