-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ConfigArgParse instead of argparse, to support getting parameters from config file and/or env vars. #1167
Use ConfigArgParse instead of argparse, to support getting parameters from config file and/or env vars. #1167
Conversation
… from config file and/or env vars.
I like how this change only required me to change 3 lines of code (or really just one line of code, and two lines regarding imports) ❤️ Python |
Codecov Report
@@ Coverage Diff @@
## master #1167 +/- ##
=========================================
+ Coverage 79.31% 79.41% +0.1%
=========================================
Files 20 20
Lines 1895 1895
Branches 294 294
=========================================
+ Hits 1503 1505 +2
+ Misses 320 319 -1
+ Partials 72 71 -1
Continue to review full report at Codecov.
|
…llow clicking it in your terminal.
Great! It'd be nice to have a simple test for the arg parsing, and one that checks that the environment variable settings work. We would probably have to make Also, maybe it's worth adding a short example to the Documentation as well? For someone unfamiliar with ConfigArgParse I imagine that this section can seem a bit dense. |
Hmm... I tried adding a test case but ended up breaking parse_options instead. I dont think we need a test, because we're only relying on normal ConfigArgParse functionality. There is a short example to the docs, do you think I should add more? I dont want to bloat the "quickstart" section. The link goes to the right place (config file syntax explanation) for configargparse on desktop (which should be readable to a programmer), but doesnt work on mobile. Maybe that's what happened? |
What I could do (without changing the method signature & breaking stuff) is test reading from config & env vars (but not overriding on command line) |
As long as ConfigArgParse doesn't change their API or break in some future version, it should be fine. But I still think it would be nice to have an integration test for that. I've added a test for
Ah, nice! For some reason I had missed the environment variable example.
To me that page feels much more targeted towards users of ConfigArgParse (which makes sense). The first paragraph talks about implementation details of ConfigArgParse. Also it mentions two different file syntaxes for config files. I assume we use the default one, but maybe not clear to Locust end users? Though we could always improve the documentation later. |
Will do! I figured out that the issue I was having was with config files, not with adding an argument to parse: My main config file, in ~/.locust.conf, was interfering with the tests! I'm looking at a workaround, either by temporarily changing $HOME in the tests (ugly) or detecting that we are running a test in parse_options (also ugly)
Users can use any of the different syntaxes, ConfigArgParse detects which one you are using. |
…parameters-from-conf-file-and-env-vars
Maybe you could add a |
Good idea. I'll try that. |
…onfig file & configuration via env vars.
locust/test/test_parser.py
Outdated
@@ -32,3 +33,16 @@ def test_skip_log_setup(self): | |||
] | |||
opts = self.parser.parse_args(args) | |||
self.assertEqual(opts.skip_log_setup, True) | |||
|
|||
def test_parameter_parsing(self): | |||
conf_file = '/tmp/locust.conf' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use NamedTemporaryFile here? (https://docs.python.org/2/library/tempfile.html#tempfile.NamedTemporaryFile)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll change that!
Agreed. The second change you took a screenshot of should also use 0 as port, instead of hardcode 8888. |
…ware firewalls). Piggybacking on this PR.
…t code is run in zmqrpc depending on whether the port is zero (randomize port) or not. Codecov warning was actually correct!
@heyman LGTY? |
Looks good! |
Solves #1166