我想从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)
我应该添加什么才能获得我的覆盖报告?
发布于 2015-05-16 22:26:07
见鬼,耶!在对Nose Test进行了一些小的调试之后,我已经成功地做到了!
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-13 01:35:02
编辑:要使用nose.run()运行插件,您需要使用' plugins‘关键字:
http://nose.readthedocs.org/en/latest/usage.html#using-plugins
您的代码已经设置好了--您需要通过runner启用覆盖率。只需像这样运行鼻部:
nosetests --with-coverage
这里有更多选项:
http://nose.readthedocs.org/en/latest/plugins/cover.html
仅供参考,您可能需要运行以下命令来获取覆盖包:
pip install coverage
https://stackoverflow.com/questions/30197717
复制相似问题