首页 文章

NoseTest:使用Python脚本覆盖运行

提问于
浏览
2

我想从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)

我应该添加什么来获取我的报道?

2 回答

  • 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
    
  • 0

    地狱啊!经过鼻子测试的一些小调试后,我成功了!

    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])
    

相关问题