[TIP] Using coverage from API and command line gives different results

Ned Batchelder ned at nedbatchelder.com
Tue Feb 11 17:44:13 PST 2014


On 2/11/14 11:50 AM, Alexander Todorov wrote:
> Hello folks,
> I'm fairly new to coverage but I've noticed something strange. With 
> the sample Python scripts (attached) which include modules I see the 
> following:
>
> If starting coverage from its API the report says:
>
> # ./myprog
> Hello __main__
> Hello mymodule1
> Hello mymodule2
>
> # coverage report
> Name        Stmts   Miss  Cover
> -------------------------------
> mymodule1       2      0   100%
> mymodule2       2      0   100%
> -------------------------------
> TOTAL           4      0   100%
>
>
> If starting coverage from the command line:
>
> # coverage run ./myprog2
> Hello __main__
> Hello mymodule1
> Hello mymodule2
>
> # coverage report
> Name        Stmts   Miss  Cover
> -------------------------------
> mymodule1       2      0   100%
> mymodule2       2      0   100%
> myprog2         5      0   100%
> -------------------------------
> TOTAL           9      0   100%
>
>
>
> The difference as seen is that the main program file is not reported. 
Because of the way coverage measurement works in CPython, it can only 
start measuring coverage at a function call.  Your myprog.py calls 
coverage.start(), which makes coverage measurement start at the next 
function call, which is into another module.  None of the code in 
myprog.py is measured because none of it happens within a function 
called between .start() and .end().
> On a larger project I'm trying to integrate coverage with I see 
> exactly the opposite - the main program file is included in the report 
> while the modules it includes are not (not all of them). All modules 
> are in site-packages.
This sound like a separate problem, perhaps your modules are imported 
before coverage starts?

--Ned.
>
>
> This is with coverage-3.7 on Fedora 20.
>
>
> Any ideas or comments ? Is this a known issue or a bug?
>
>
> Regards,
> Alex
>
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140211/c26ac341/attachment.htm>


More information about the testing-in-python mailing list