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
add ifmain check to setup.py #1745
Conversation
Could you unpack the description a little bit more? Is the goal here to prevent someone from running More generally, it's not considered necessary to test a Suppose you have a simple script: #!/usr/bin/env python
from sys import exit
from package.subpackage import main
exit(main()) And def do_stuff():
return 0
def main():
status = do_stuff()
return status And from ..subpackage import do_stuff
def test_do_stuff():
assert do_stuff() == 0 This test pattern should eliminate any need to hide things in |
Thanks for taking a look at this. Clarifying: The goal is to re-enable support for "python setup.py test" in case someone like me types that even if they were supposed to type "pytest" instead. The problem was that Related: the symptom was the same as desihub/redrock#209 where rrdesi multiprocessing was broken on newer python until a |
I would just change my habits. You really, really need to get into the habit of not using |
In the meantime, is there any actual harm to having an ifmain guard in setup.py? |
I really don't know. All I can say is that I have never seen a |
Thanks for the comments. Although it's non-standard to use I'll try to remember to use pytest in the future, but there is one feature of "python setup.py test -m desispec.test.test_blah" that pytest doesn't seem to support: adding |
FYI: Using pytest one can do things like this |
Context: I recently upgraded my laptop base conda installation to use python 3.9.12, which effectively broke unit tests started via "python setup.py test". I know the new procedure is to use pytest instead, but old habits die hard...
Symptom: The test_binscripts test of
desispec.scripts.stdstars.main
when called as a function (but not when called via a spawned script) would go crazy on the multiprocessing, and start running multiple versions of the test including multiple lines like "running build_ext", sometimes printing the message:See desihub/redrock#209 as well. The test would run fine if launched via pytest or by directly running
python py/desispec/test/test_binscripts.py
.Solution: Add
if __name__ == '__main__':
guard to setup.py itself.Help Wanted: does anyone know any potential negative side effects from this, e.g. interactions with pip? setup.py is a bit of a special thing, different from our standard bin/* scripts so I'd appreciate a second opinion on this. @weaverba137 @dkirkby or others?