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

Terry Reedy tjreedy at udel.edu
Wed May 1 01:12:10 EDT 2019


On 4/30/2019 5:24 PM, Chris Withers wrote:
> Hi All,
> 
> I have a crazy idea of getting unittest.mock up to 100% code coverage.
> 
> I noticed at the bottom of all of the test files in testmock/, there's a:
> 
> if __name__ == '__main__':
>      unittest.main()
> 
> ...block.

Such blocks should be excluded from coverage by the default .coveragerc 
file.  Mine came with

exclude_lines =
     # Don't complain if non-runnable code isn't run:
     if 0:
     if __name__ == .__main__.:
     if DEBUG:


-- 
Terry Jan Reedy




More information about the Python-Dev mailing list