Skip to content

Commit b4138a4

Browse files
authored
Merge pull request #3257 from locustio/fix-single-line-conf-files-incorrectly-being-treated-as-toml
Fix single line .conf files incorrectly being treated as toml
2 parents d1da1ee + f5631cf commit b4138a4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

locust/argument_parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def parse(self, stream):
133133
else:
134134
result[key] = str(value)
135135
break
136+
else:
137+
if not stream.name.endswith("toml"):
138+
raise configargparse.ConfigFileParserException("Not a toml file. Fall back to DefaultConfigFileParser.")
136139

137140
return result
138141

locust/test/test_parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ def test_parse_options_from_conf_file(self):
5858
self.assertEqual(["Critical", "Normal"], options.tags)
5959
self.assertEqual("https://example.com", options.host)
6060

61+
def test_parse_single_line_conf_file(self): # there was an issue with conf files identified as toml
62+
with NamedTemporaryFile(mode="w", suffix=".conf") as file:
63+
config_data = "users = 10\n"
64+
file.write(config_data)
65+
file.flush()
66+
parser = get_parser(default_config_files=[file.name])
67+
options = parser.parse_args()
68+
69+
self.assertEqual(10, options.num_users)
70+
6171
def test_parse_options_from_toml_file(self):
6272
with NamedTemporaryFile(mode="w", suffix=".toml") as file:
6373
config_data = """\

0 commit comments

Comments
 (0)