Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57481

Re: Python Coverage: testing a program

Date 2013-10-24 19:53 -0400
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: Python Coverage: testing a program
References (3 earlier) <526908b2$0$29981$c3e8da3$5496439d@news.astraweb.com> <52695CFB.9010309@nedbatchelder.com> <526984F3.3040905@udel.edu> <7weh7acrv8.fsf_-_@benfinney.id.au> <52699EFE.3070904@stoneleaf.us>
Newsgroups comp.lang.python
Message-ID <mailman.1490.1382658834.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 10/24/13 6:28 PM, Ethan Furman wrote:
> On 10/24/2013 01:54 PM, Ben Finney wrote:
>> Terry Reedy <tjreedy@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.  ;)
>

Sure, if that line appears in program.py, then it will be run if you 
execute program.py:  $ coverage run program.py

You can run coverage a number of times, even with different main 
programs, then combine all the data to produce a combined report. This 
way you could cover all of the __main__ clauses in a number of files.

--Ned.

> -- 
> ~Ethan~
>
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Maintaining a backported module Steven D'Aprano <steve@pearwood.info> - 2013-10-24 04:54 +0000
  Re: Maintaining a backported module Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 16:09 +1100
    Re: Maintaining a backported module Metallicow <metaliobovinus@gmail.com> - 2013-10-23 22:46 -0700
      Re: Maintaining a backported module Metallicow <metaliobovinus@gmail.com> - 2013-10-30 03:32 -0700
  Re: Maintaining a backported module Paul Rubin <no.email@nospam.invalid> - 2013-10-23 22:38 -0700
  Re: Maintaining a backported module Ethan Furman <ethan@stoneleaf.us> - 2013-10-23 23:30 -0700
  Re: Maintaining a backported module Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 17:59 +1100
    Re: Maintaining a backported module Steven D'Aprano <steve@pearwood.info> - 2013-10-24 09:38 +0000
      Re: Maintaining a backported module Ben Finney <ben+python@benfinney.id.au> - 2013-10-24 21:01 +1100
  Re: Maintaining a backported module Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-24 09:00 +0200
  Re: Maintaining a backported module Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-24 09:37 +0100
  Re: Maintaining a backported module Ned Batchelder <ned@nedbatchelder.com> - 2013-10-24 06:36 -0400
    Re: Maintaining a backported module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-24 11:46 +0000
      Re: Maintaining a backported module rusi <rustompmody@gmail.com> - 2013-10-24 05:25 -0700
      Re: Maintaining a backported module Ned Batchelder <ned@nedbatchelder.com> - 2013-10-24 13:46 -0400
      Re: Maintaining a backported module Terry Reedy <tjreedy@udel.edu> - 2013-10-24 16:37 -0400
      Python Coverage: testing a program (was: Maintaining a backported module) Ben Finney <ben+python@benfinney.id.au> - 2013-10-25 07:54 +1100
      Re: Python Coverage: testing a program Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-24 22:55 +0100
      Re: Python Coverage: testing a program Terry Reedy <tjreedy@udel.edu> - 2013-10-24 18:36 -0400
      Re: Python Coverage: testing a program Ethan Furman <ethan@stoneleaf.us> - 2013-10-24 15:28 -0700
      Re: Python Coverage: testing a program Ben Finney <ben+python@benfinney.id.au> - 2013-10-25 10:27 +1100
      Re: Python Coverage: testing a program Ben Finney <ben+python@benfinney.id.au> - 2013-10-25 10:30 +1100
      Re: Python Coverage: testing a program Ned Batchelder <ned@nedbatchelder.com> - 2013-10-24 19:53 -0400
      Re: Python Coverage: testing a program Terry Reedy <tjreedy@udel.edu> - 2013-10-24 19:55 -0400
      Re: Maintaining a backported module Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-10-25 08:49 +0100
  Re: Maintaining a backported module Christian Heimes <christian@python.org> - 2013-10-24 12:47 +0200
  Re: Maintaining a backported module Ethan Furman <ethan@stoneleaf.us> - 2013-10-24 12:42 -0700

csiph-web