如何通过 Nose 获取测试次数 运行?

How to get number of tests run by Nose?

Nose 以编程方式启动:

test_argv = ['nosetests', '-a', 'level=gold', '--with-id']

if __name__ == '__main__':
    result = nose.run(argv=test_argv)

出于报告目的,我想记录通过鼻子运行进行了多少次测试

Nose 的控制台输出有多少测试运行。

------------------------------------
Ran 294 in x.x seconds

关于如何访问该号码的任何想法?

(不幸的是,result 是一个布尔值,所以它没有帮助...)

您总是可以 运行 --with-xunit plugin 生成 xml 文件并从中读取测试编号

nosetests --collect-only 可以给出测试用例的数量。