[Python-Dev] "if __name__ == '__main__'" at the bottom of python unittest files

Chris Withers chris at withers.org
Wed May 1 08:56:44 EDT 2019

Sorry, accidentally include a comment for this in a reply to Paul:

On 01/05/2019 13:39, Serhiy Storchaka wrote:
> We try to support several different ways of running tests. This allows 
> to catch some environment depended flaws in tests and serves as a kind 
> of the test of unittest itself. Not all test files are made discoverable 
> yet, but we move in this direction.

I'm not sure I understand how triggering via unittest or via unittest 
(no typo, both these __main__ blocks and python -m unittest are using 
the same test runner) could make a difference.

And sorry, to be clear, I'm only taking about the ones in 
unittest/mock/testmock - Rob Collins confirmed these where never needed 
in a private reply:

> They were never needed 😁
> Removal is fine with me.


More information about the Python-Dev mailing list