diff --git a/mobly/config_parser.py b/mobly/config_parser.py index 72f3883e..4aa3187a 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 46548f0f..327e531f 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))