-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Allow sys.argv and args with LightningCLI for testing #16807
Comments
This is not necessary. You can patch |
I don't like monkeypatching when I can get away with not doing it. Regardless, patching doesn't work / make sense for all testing frameworks like xdoctest. |
If circumventing this exception is only relevant for your tests, why not use this extension class you already wrote in your test suite? def parse_arguments(...):
try:
super().parse_arguments():
except ValueError:
# we are testing, ignore exception
do_something() I would rather not adapt the implementation for a specific testing requirement. It is preferred that tests are adapted instead (for example by monkeypatching). |
The main place it is relevant is tests. There is also the case that if you invoke IPython with args then it will also error. This is not the case yet, but I do envision a system where other tools (that might have their own sys.argv) are invoking our fit method (implemented via LightningCLI) programatically. Of course I can just keep my patched version, but as I've said, I prefer to not patch whenever possible. What I'd like to know is: is there a technical reason why sys.argv should not be populated when running with args? For instance, when running with different strategies, will there be issues if sys.argv is not empty? Or is it the case that when args is specified sys.argv might as well be empty? If removing the exception actually breaks something, then my comment ends here, but if not then I'll make this point: For me, running into this error was surprising and took me a while to figure out how to work around it. Was this feature introduced because users were making mistakes thinking that sys.argv would be respected even if args was given? In other words: is this a case of preemptiveness? Or is this really stopping people from making mistakes. My arm-chair thought is that: if you are passing in |
The reason why this was added is only this comment #14596 (comment). I am neutral about removing this. |
Outline & Motivation
I currently am forced to inherit from
LightningCLI
and overloadparse_arguments
to disable an error when you call LightningCLI withargs
andsys.argv
is populated.The reason I'm doing this is testing. I have automated tests and doctests that ensure our LightningCLI scripts play nice with our models / dataloaders. However, when I run testing software like
pytest
orxdoctest
, thesys.argv
list is populated, but in my test I call LightningCLI programatically with a dictionary config.Pitch
It would be nice if this was either changed to a warning, or allow the user to pass a flag that makes the error a warning.
If the maintainers think this is a good idea I can write the PR.
Additional context
No response
cc @Borda @justusschock @awaelchli @carmocca @mauvilsa
The text was updated successfully, but these errors were encountered: