Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python nosetests with coverage no longer shows missing lines

Tags:

I've been using the following command to run tests and evaluate code coverage for a Python project for over a year now.

nosetests -v --with-coverage --cover-package=genhub genhub/*.py 

The coverage report used to include a column on the far right showing the lines missing coverage.

Name                 Stmts   Miss Branch BrPart  Cover   Missing ---------------------------------------------------------------- genhub/cdhit.py         50      0      8      0   100%    genhub/exons.py         85     69      8      0    17%   24-40, 48-56, 60-79, 87-107, 129-132, 138-141, 147-150 genhub/fasta.py         76      0     26      0   100%    genhub/genomedb.py     205    153     48      0    21%   40-43, 53-60, 64-65, 70, 74, 82, 86, 90, 98-99, 103-104, 108-109, 113-114, 118-119, 123-124, 128-129, 143-144, 152-154, 158-160, 164-166, 175, 180, 240-280, 289, 292, 295, 308-317, 323-330, 351-377, 380-386, 396-413, 419-430, 436-443, 449-456 genhub/iloci.py        112     91      8      0    18%   30-46, 54-64, 73-90, 102-118, 127-142, 165-173, 179-183, 189-193, 199-207, 213-225 genhub/mrnas.py        121    108     24      0     9%   30-63, 79-105, 118-158, 178-197, 203-226 genhub/pdom.py          95     68     24      0    23%   31-32, 35, 39, 43, 47, 50-53, 56-59, 62-64, 67-72, 75-106, 116-119, 126-128, 134-141, 148-156 genhub/proteins.py      20     13      2      0    32%   43-53, 94-97 genhub/refseq.py       237    195     44      0    15%   30-46, 49, 53, 57, 61, 65, 69, 73, 76-86, 89-115, 118-127, 130-178, 189-211, 217-226, 232-242, 248-265, 271-288, 294-297, 303-310, 317-326, 333-374, 380-387 genhub/registry.py     126     90     32      2    24%   48-56, 59-64, 67-69, 72-77, 81-83, 92-94, 103-109, 112-113, 116-117, 142-168, 174-188, 194-201, 207-216, 40->44, 44->48 genhub/stats.py          3      0      0      0   100%    genhub/tair.py         128     97     22      0    21%   32-42, 45, 49, 53, 57, 61, 65, 69, 73, 76-79, 82-104, 110-119, 122-154, 165-180, 186-189, 195-203, 210-221 ---------------------------------------------------------------- TOTAL                 1258    884    246      2    27%    ---------------------------------------------------------------------- Ran 46 tests in 0.033s  FAILED (errors=41) 

However, the Missing column no longer shows up for me (nose version 1.3.7, coverage.py version 4.1).

I'm aware nose is no longer being supported. Is this change related to that, or something in coverage.py, or both?

like image 923
Daniel Standage Avatar asked Jun 09 '16 18:06

Daniel Standage


2 Answers

In coverage.py 4.1, I fixed a problem with the coverage.py API defaulting two parameters to non-None values. One of them was show_missing.

The best way to fix this in your project is to set show_missing in your .coveragerc file:

# .coveragerc [report] show_missing = True 
like image 155
Ned Batchelder Avatar answered Dec 21 '22 00:12

Ned Batchelder


Beside having a configuration files to set show_missing you can also use coverage set_option to define it.

cov.set_option('report:show_missing', True) 

I have issue with getting the correct coverage for models.py, i solve it according to this.

Then i just add the above lines to show missing line. So my manage.py have a part like this:

if is_testing:     import coverage     cov = coverage.coverage(source=['blog'], omit=['*/tests/*'])     cov.set_option('report:show_missing', True) #add this     cov.erase()     cov.start() 
like image 44
Zac Kwan Avatar answered Dec 21 '22 02:12

Zac Kwan