64

I can't seem to get code coverage with Nose to work, despite having the plugin installed.

Any ideas on how to fix this?

12:15:25 ~/sandbox/ec$ nosetests --plugins
Plugin xunit
Plugin deprecated
Plugin skip
Plugin multiprocess
Plugin failuredetail
Plugin capture
Plugin logcapture
Plugin coverage
Plugin attributeselector
Plugin doctest
Plugin profile
Plugin id
Plugin allmodules
Plugin collect-only
Plugin isolation
Plugin pdb

12:15:34 ~/sandbox/ec$ nosetests -v --with-coverage
nose.plugins.cover: ERROR: Coverage not available: unable to import coverage module
tests.edgecast_client_tests.test_log ... ok

----------------------------------------------------------------------
Ran 1 test in 0.206s

OK
oz123
  • 27,559
  • 27
  • 125
  • 187
doremi
  • 14,921
  • 30
  • 93
  • 148

2 Answers2

104

Have you tried pip install coverage? The coverage plugin depends on separate coverage module, which is not a nose's dependency, so needs to be installed manually.

jkozera
  • 3,016
  • 2
  • 16
  • 11
  • 4
    on debian/ubuntu you could install via `apt-get install python-coverage` as well – mnagel Aug 29 '13 at 17:46
  • 3
    I've installed it both ways and it still gives me the same error. – Diego Pamio Mar 09 '14 at 20:51
  • 3
    I received the same error in the original question even though I have the coverage package installed in my virtualenv. My problem was that the nosetests command was coming from my system-wide installation of nose, and I didn't have coverage installed system-wide. By prepending the full path to the executable in my virtualenv, /path/to/virtualenv/bin/nosetests --with-coverage worked. – Joseph Sheedy Mar 24 '14 at 22:35
  • @velotron Strangely, the same solution worked for me despite the fact that I don't have a system-wide installation of nose – Brad Pitcher Apr 19 '14 at 17:40
  • 2
    @mnagel @Diego You may need to use `apt-get install python3-coverage` if you have Python3. – Eugene Yarmash Mar 11 '15 at 14:19
  • @velotron I tried installing `nose` into my virtualenv (along with `coverage`), which seemed to work. – BenjaminGolder Sep 01 '15 at 01:20
  • My virtualenv has python3.4.2. I did `pip install coverage` and the issue went away. So the accepted answer worked for me. – HelloWorld101 Aug 03 '17 at 10:42
  • Updating both packages `pip install coverage -U` and `pip install nose -U` did it for me. But with older nose (1.3.0) I am getting coverage (4.0.3) that shows me which line numbers are not covered. – radtek Nov 08 '17 at 20:41
2

Validate if the coverage module is working by itself via coverage --version. I had a case that it was not working due to the lack of SQLite modules in my python installation from the source. I reinstalled python with SQLite extension to fix the issue.

  • See https://stackoverflow.com/questions/1210664/no-module-named-sqlite3/38842600#38842600 for details when using `pyenv`. – kap Jan 04 '22 at 21:13