如何在 Eclipse + Pydev 中获得单元测试覆盖率结果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2262777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get unit test coverage results in Eclipse + Pydev?
提问by Jader Dias
I know Eclipse + PyDev has an option Run As
=> 3 Python Coverage
. But all it reports is:
我知道 Eclipse + PyDev 有一个选项Run As
=> 3 Python Coverage
。但它报告的只是:
Ran 6 tests in 0.001s
OK
在 0.001 秒内运行 6 次测试
好的
And it says nothing about code coverage. How to get a code coverage report in Pydev?
它没有说明代码覆盖率。如何在 Pydev 中获取代码覆盖率报告?
采纳答案by AndiDog
- Run a file with "Python Coverage"
- Window > Show View > Code Coverage Results View
- Select the directory in which the executed file is
- Double-click on the executed file in the file list
- Statistics are now at the right, not executed lines are marked red in the code view
- 运行带有“Python Coverage”的文件
- 窗口 > 显示视图 > 代码覆盖率结果视图
- 选择执行文件所在的目录
- 双击文件列表中执行的文件
- 统计现在在右侧,未执行的行在代码视图中标记为红色
Actually this is a really nice feature, didn't know about it before :)
实际上这是一个非常好的功能,之前不知道它:)
回答by Fabio Zadrozny
Note that in pydev 2.0, the coverage support changed, now, you should first open the coverage view and select the 'enable code coverage for new launches'... after that, any launch you do (regular or unit-test) will have coverage information being gathered (and the results inspection also became a bit more intuitive).
请注意,在 pydev 2.0 中,覆盖支持发生了变化,现在,您应该首先打开覆盖视图并选择“为新启动启用代码覆盖”……之后,您所做的任何启动(常规或单元测试)都将具有正在收集覆盖信息(结果检查也变得更加直观)。
回答by sttwister
See if this helps http://www.machine-envy.com/blog/2006/07/29/automated-python-testing-with-nose-and-eclipse/
看看这是否有帮助http://www.machine-envy.com/blog/2006/07/29/automated-python-testing-with-nose-and-eclipse/
It uses nosetests with the –with-coverage
option.
它使用带有–with-coverage
选项的鼻子测试。