Python Coverage: testing a program

Ethan Furman ethan at stoneleaf.us
Thu Oct 24 18:28:14 EDT 2013


On 10/24/2013 01:54 PM, Ben Finney wrote:
> Terry Reedy <tjreedy at udel.edu> writes:
>
>> On 10/24/2013 1:46 PM, Ned Batchelder wrote:
>>> It's been fun dropping the contortions for coverage.py 4.x, though!
>>
>> One request: ignore "if __name__ == '__main__':" clauses at the end of
>> files, which cannot be run under coverage.py, so 100% coverage is
>> reported as 100% instead of 9x%.
>
> You can do this already with current Coverage: tell Coverage to exclude
> <URL:http://nedbatchelder.com/code/coverage/excluding.html> specific
> statements, and it won't count them for coverage calculations.

While that's neat (being able to exclude items) is there any reason to 
ever count the `if __name__ == '__main__'` clause?  Are there any 
circumstances where it could run under Coverage?  (Apologies if this is 
a dumb question, I know nothing about Coverage myself -- but I'm going 
to go look it up now.  ;)

--
~Ethan~





More information about the Python-list mailing list