nosetests 无法导入 virtualenv 的覆盖范围

nosetests unable to import coverage with virtualenv

我已经在我的虚拟环境中安装了 nosecoverage,但是它不起作用

(venv) ../my_cookbook$ nosetests --with-coverage

nose.plugins.cover: ERROR: Coverage not available: unable to import coverage module

我想知道它是否以某种方式逃脱了我的 venv,所以我尝试了这个并且成功了!

(venv) ../my_cookbook$ ./venv/bin/nosetests --with-coverage

然后我想看看我的路径是不是有点乱。

(venv) ../my_cookbook$ which nosetests

/home/peter/Projects/my_cookbook/venv/bin/nosetests

(venv) ../my_cookbook$ which coverage

/home/peter/Projects/my_cookbook/venv/bin/coverage

那么这是怎么回事? nosetests 命令以某种方式逃脱了我的 virtualenv,但我不知道如何转义。

不幸的是,我没有解释为什么 nose 插件没有覆盖,但是,通过 coverage 执行测试应该是首选而不是使用测试 运行ner 插件(在你的情况下是鼻子覆盖插件)。 (报道作者):

using a plugin means you are depending on that plugin's behavior being correct and understandable. In the name of being helpful, plugins will have their own logic that may have been the best idea when they were written, but the test runner and/or coverage.py may have changed in the meantime. The plugins tend not to be as well-maintained as the other components. If you can avoid them, you have one less thing to think about.

换句话说,运行:

$ coverage run -m nose

并获取覆盖率报告:

$ coverage report