How to Fix Python Nose: Coverage not available: unable to import coverage module
Asked Answered
M

2

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
Melamine answered 23/1, 2013 at 20:17 Comment(0)
P
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.

Phelps answered 23/1, 2013 at 20:28 Comment(8)
on debian/ubuntu you could install via apt-get install python-coverage as wellExorcist
I've installed it both ways and it still gives me the same error.Firehouse
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.Calabresi
@velotron Strangely, the same solution worked for me despite the fact that I don't have a system-wide installation of noseDamascus
@Exorcist @Diego You may need to use apt-get install python3-coverage if you have Python3.Nur
@velotron I tried installing nose into my virtualenv (along with coverage), which seemed to work.Tanh
My virtualenv has python3.4.2. I did pip install coverage and the issue went away. So the accepted answer worked for me.Geest
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.Volcano
V
3

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.

Vanhomrigh answered 11/6, 2021 at 5:58 Comment(1)
See https://mcmap.net/q/116540/-no-module-named-_sqlite3/… for details when using pyenv.Violence

© 2022 - 2024 — McMap. All rights reserved.