【问题标题】:How to Fix Python Nose: Coverage not available: unable to import coverage module如何修复 Python Nose:覆盖不可用:无法导入覆盖模块
【发布时间】:2013-01-23 20:17:53
【问题描述】:

尽管安装了插件,但我似乎无法使用 Nose 获得代码覆盖率。

关于如何解决这个问题的任何想法?

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

【问题讨论】:

    标签: python nose coverage.py python-coverage


    【解决方案1】:

    你试过pip install coverage吗?覆盖插件依赖单独的覆盖模块,不是鼻子的依赖,需要手动安装。

    【讨论】:

    • 在 debian/ubuntu 上你也可以通过 apt-get install python-coverage 安装
    • 我已经安装了两种方式,它仍然给我同样的错误。
    • 我在原始问题中收到了同样的错误,即使我的 virtualenv 中安装了覆盖包。我的问题是nosetests 命令来自我在系统范围内安装的nose,并且我没有在系统范围内安装覆盖。通过在我的 virtualenv 中添加可执行文件的完整路径, /path/to/virtualenv/bin/nosetests --with-coverage 起作用了。
    • @velotron 奇怪的是,尽管我没有在系统范围内安装鼻子,但同样的解决方案对我有用
    • @mnagel @Diego 如果你有 Python3,你可能需要使用apt-get install python3-coverage
    【解决方案2】:

    通过coverage --version 验证覆盖模块是否自行工作。我有一个案例,由于我从源代码安装的 python 中缺少 SQLite 模块,它无法正常工作。我重新安装了带有 SQLite 扩展的 python 来解决这个问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 2012-09-11
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-04-05
    相关资源
    最近更新 更多