Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get coverage report from a given package using nose2

I would like to use nose2 with coverage plugin to get the coverage of a Python package but I'm have a hard time configuring it to cover only the package I'm working on. The package is called vimhdl and the coverage section of my unittest.cfg looks like this:

[coverage]
coverage = vimhdl

With nose2, the result doesn't include all files from the package (maybe because of Coverage.py warning: Module vimhdl was previously imported, but not measured. message, but I don't know how to fix it).

Also, when opening the HTML report for a given file, statements such as import logging and modules' doc strings are marked as not covered.

$ nose2 --with-coverage   -vvv
...
----------------------------------------------------------------------
Ran 5 tests in 0.166s

OK
Coverage.py warning: Module vimhdl was previously imported, but not measured.
---------- coverage: platform linux2, python 2.7.10-final-0 ----------
Name                                  Stmts   Miss  Cover
---------------------------------------------------------
python/vimhdl/compilers/__init__.py      95     42    56%
python/vimhdl/compilers/ghdl.py          92     41    55%
python/vimhdl/config_parser.py           74     42    43%
python/vimhdl/project_builder.py        269    164    39%
python/vimhdl/source_file.py            126     51    60%
---------------------------------------------------------
TOTAL                                   656    340    48%

On the other hand, with nosetests, the result include all files as expected.

$ nosetests --with-coverage -vvv

Name                           Stmts   Miss  Cover   Missing
------------------------------------------------------------
vimhdl.py                          5      0   100%   
vimhdl/compilers.py               95     11    88%   46-47, 97, 106-108, 131-132, 149-150, 158
vimhdl/compilers/fallback.py      22      7    68%   31-32, 35, 38, 41, 44, 47
vimhdl/compilers/ghdl.py          92     21    77%   91-94, 107-108, 151-172, 182
vimhdl/compilers/msim.py          94     72    23%   49, 52-69, 73-102, 113-124, 128-135, 138-151, 154-159, 163-169, 176-179, 185-190
vimhdl/compilers/xvhdl.py         61     46    25%   38-40, 44-51, 54-76, 87-98, 101-105, 110-126
vimhdl/config.py                  69     46    33%   21-22, 55-77, 81-83, 87-91, 95-105, 109-122, 126-135
vimhdl/config_parser.py           74     25    66%   33-34, 45-46, 50, 53-88, 117, 119, 124, 133
vimhdl/exceptions.py              12      4    67%   21, 24, 28, 31
vimhdl/project_builder.py        269    114    58%   23-24, 61-68, 92, 97, 102, 108, 115-121, 131-134, 139-146, 156, 169-170, 182-185, 205-219, 221, 237-273, 278-313, 332-336, 368-371, 373-376, 380-381, 384-385, 393-394, 400, 419-426, 430-431, 455-456, 462-476
vimhdl/source_file.py            126     25    80%   71, 86-87, 168, 172, 174, 176, 178, 197-198, 203-216, 219
vimhdl/static_check.py           104     88    15%   56-112, 119-132, 139-165, 169-188, 191-197, 200
vimhdl/utils.py                    8      5    38%   24-28
------------------------------------------------------------
TOTAL                           1031    464    55%   

How do I configure nose2 coverage plugin to cover only a given module?

The source code is on github at https://github.com/suoto/vim-hdl/tree/unstable if it helps.

like image 947
suoto Avatar asked Jan 01 '16 23:01

suoto


People also ask

How do I activate a coverage report in nosetests?

Check nosetests --help or nosetests --plugins to find out which coverage plugin is available on your system. If you have Ned Batchelder’s coverage module installed, you may activate a coverage report with the --with-coverage switch or NOSE_WITH_COVERAGE environment variable.

What is [nose_cover_Min_percentage]?

Minimum percentage of coverage for tests to pass [NOSE_COVER_MIN_PERCENTAGE] Include all python files under working directory in coverage report. Useful for discovering holes in test coverage if not all files are imported by the test suite. [NOSE_COVER_INCLUSIVE] class nose.plugins.cover. Coverage ¶

Does nose2 support parallel test execution?

By default, Nose2 does not support parallel test execution, a feature that is extensively used in test automation. However, loading plugins is not tricky in Nose2, as plugin module names can be effortlessly added to the plugins list in the config file’s [unittest] section.

How to include modules in nose_cover_tests?

If you want to include those modules too, use the ``--cover-tests`` switch, or set the NOSE_COVER_TESTS environment variable to a true value.


1 Answers

The simplest way to control coverage.py is to use it to run your tests:

coverage run --source=vimhdl -m nose 
like image 103
Ned Batchelder Avatar answered Oct 29 '22 05:10

Ned Batchelder