Error in representation of modules/packages in coverage report

Issue #388 invalid
Lars Butler created an issue

Using the latest version of the code (2260:274760da6e80), I'm seeing some strange issues with coverage report output when using nosetests --with-coverage. It seems like a lot of this code was changed between version 3.7.x and version 4.0x.

Here's how to reproduce what I'm seeing. First, create a trivial empty python package:

$ mkdir mylib
$ touch mylib/__init__.py
$ touch mylib/foo.py

When running tests, here's what I see:

$ nosetests --with-coverage --cover-package=mylib

Name       Stmts   Miss  Cover   Missing
----------------------------------------
mylib.py       0      0   100%   
----------------------------------------------------------------------
Ran 0 tests in 0.002s

OK
$ nosetests --with-coverage --cover-package=mylib/

Name                Stmts   Miss  Cover   Missing
-------------------------------------------------
mylib/__init__.py       0      0   100%   
mylib/foo.py            0      0   100%   
-------------------------------------------------
TOTAL                   0      0   100%   
----------------------------------------------------------------------
Ran 0 tests in 0.002s

OK

The second example using --cover-package=mylib/ looks correct, but for --cover-package=mylib, I would expect to see this:

$ nosetests --with-coverage --cover-package=mylib

Name                Stmts   Miss  Cover   Missing
-------------------------------------------------
mylib       0      0   100%   
mylib.foo            0      0   100%   
-------------------------------------------------
TOTAL                   0      0   100%   
----------------------------------------------------------------------
Ran 0 tests in 0.002s

OK

Comments (4)

  1. Ned Batchelder repo owner

    @larsbutler Has this behavior changed between 3.7.1 and 4.0? I don't support the nose-coverage plugin so I'm not sure exactly what it is doing, but I would be interested to know if it's changed between coverage.py 3.7.1 and 4.0.

  2. Lars Butler reporter

    Okay, it seems that the particular issue I reported (about mylib.py) was fixed between 4.0a5 and 4.0a6.

    There is a slight difference between 3.7.1 and 4.0. To illustrate, I've wrapped everything up in a simple tox configuration. Output is below. Note the package versions.

    $ tox -r
    GLOB sdist-make: /private/tmp/mylib/setup.py
    cov3 create: /private/tmp/mylib/.tox/cov3
    cov3 installdeps: -r/private/tmp/mylib/requirements3.txt
    cov3 inst: /private/tmp/mylib/.tox/dist/mylib-0.1.zip
    cov3 installed: coverage==3.7.1,mylib==0.1,nose==1.3.7,wheel==0.24.0
    cov3 runtests: PYTHONHASHSEED='2628991933'
    cov3 runtests: commands[0] | nosetests --with-coverage --cover-package=mylib
    
    Name    Stmts   Miss  Cover   Missing
    -------------------------------------
    mylib       0      0   100%   
    ----------------------------------------------------------------------
    Ran 0 tests in 0.015s
    
    OK
    cov3 runtests: commands[1] | nosetests --with-coverage --cover-package=mylib/
    
    Name             Stmts   Miss  Cover   Missing
    ----------------------------------------------
    mylib/__init__       0      0   100%   
    mylib/bar            2      2     0%   1-2
    mylib/foo            2      2     0%   1-2
    ----------------------------------------------
    TOTAL                4      4     0%   
    ----------------------------------------------------------------------
    Ran 0 tests in 0.013s
    
    OK
    cov4 recreate: /private/tmp/mylib/.tox/cov4
    cov4 installdeps: -r/private/tmp/mylib/requirements4.txt
    cov4 inst: /private/tmp/mylib/.tox/dist/mylib-0.1.zip
    cov4 installed: coverage==4.0a6,mylib==0.1,nose==1.3.7,wheel==0.24.0
    cov4 runtests: PYTHONHASHSEED='2628991933'
    cov4 runtests: commands[0] | nosetests --with-coverage --cover-package=mylib
    
    Name                Stmts   Miss  Cover   Missing
    -------------------------------------------------
    mylib/__init__.py       0      0   100%   
    ----------------------------------------------------------------------
    Ran 0 tests in 0.004s
    
    OK
    cov4 runtests: commands[1] | nosetests --with-coverage --cover-package=mylib/
    
    Name                Stmts   Miss  Cover   Missing
    -------------------------------------------------
    mylib/__init__.py       0      0   100%   
    mylib/bar.py            2      2     0%   1-2
    mylib/foo.py            2      2     0%   1-2
    -------------------------------------------------
    TOTAL                   4      4     0%   
    ----------------------------------------------------------------------
    Ran 0 tests in 0.004s
    
    OK
    ________________________________________________________________________________________________ summary _________________________________________________________________________________________________
      cov3: commands succeeded
      cov4: commands succeeded
      congratulations :)
    

    It's slightly different, but I'm not sure I would call it a bug. Sorry for the noise. It looks like the change in output is the result of changes in coveragepy as well as the nose coverage plugin.

  3. Log in to comment