4

我想从 Python 脚本运行 NoseTest。但我不仅要运行它,还要测量测试覆盖率。

刚才我有以下代码:

import os
import sys
import nose

sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))

import tests

if __name__ == "__main__":
    config = nose.config.Config(verbosity=3, stopOnError=False, argv=["--with-coverage"])
    result = nose.run(module=tests, config=config)

我应该添加什么来获取我的覆盖率报告?

4

2 回答 2

2

地狱是的!经过鼻子测试的一些小调试后,我设法做到了!

if __name__ == "__main__":
    file_path = os.path.abspath(__file__)
    tests_path = os.path.join(os.path.abspath(os.path.dirname(file_path)), "tests")
    result = nose.run(argv=[os.path.abspath(__file__),
                            "--with-cov", "--verbosity=3", "--cover-package=phased", tests_path])
于 2015-05-16T14:26:06.920 回答
0

编辑:要使用nose.run() 运行插件,您需要使用'plugins' 关键字:

http://nose.readthedocs.org/en/latest/usage.html#using-plugins

您的代码已全部设置好——您需要通过运行器启用覆盖。像这样简单地跑鼻子:

nosetests --with-coverage

这里有更多选择:

http://nose.readthedocs.org/en/latest/plugins/cover.html

仅供参考,您可能需要运行以下命令来获取覆盖包:

pip install coverage 
于 2015-05-12T17:35:02.107 回答