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

Chris Withers chris at withers.org
Wed May 1 10:20:48 EDT 2019

On 01/05/2019 14:52, Karthikeyan 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.
> Agreed. This also has helped in the past to find issues like 
> https://bugs.python.org/issue29512#msg299045.

My read of that issue is that issue is that the only problem that was 
found is that an ambiguous way of running tests, which isn't included in 
the devguide, and maybe for good reason, caused a problem which sucked 
up a bunch of Victor's time.

The reason Lib/test/ was on sys.path was because the tests were run with 
./python Lib/test/test_bisect.py, when it shouldn't be.

Had it been run with:

./ python -m test.test_bisect

...it would not have been, and bisect.py would not have needed renaming 
to bisect_cmd.py.


More information about the Python-Dev mailing list