You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unittest tests will not run with unittest.main() in the test file #17342
If you use unittest.main() then that can try to execute tests when the unittest loader loads this. So this should work better if you protect it like this. This is the recommended way of protecting code from running on import.
I should have been doing if __name__ == '__main__': anyway.
That fixed the problem.
I think it would be a good idea to make the error more explicit (i.e. to try to detect the running of the tests, and output a message to the user, saying to use if __name__ == '__main__').
Activity
karthiknadig commentedon Sep 9, 2021
If you use
unittest.main()then that can try to execute tests when the unittest loader loads this. So this should work better if you protect it like this. This is the recommended way of protecting code from running on import.TheCatSaber commentedon Sep 9, 2021
if __name__ == '__main__':anyway.I think it would be a good idea to make the error more explicit (i.e. to try to detect the running of the tests, and output a message to the user, saying to use
if __name__ == '__main__').brettcannon commentedon Sep 9, 2021
We are working on rewriting our detection/execution code which should simply ignore the initial run as a side-effect of importing.
karthiknadig commentedon Oct 27, 2021
Closing in favor of #17242