Python 代码的代码覆盖率和单元测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/272188/
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
Code Coverage and Unit Testing of Python Code
提问by bhadra
I have already visited Preferred Python unit-testing framework. I am not just looking at Python Unit Testing Framework, but also code coverage with respect to unit tests. So far I have only come across coverage.py. Is there any better option?
我已经访问过首选 Python 单元测试框架。我不仅关注 Python 单元测试框架,还关注与单元测试相关的代码覆盖率。到目前为止,我只遇到了coverage.py。有没有更好的选择?
An interesting option for me is to integrate cpython, unit testing of Python code and code coverage of Python code with Visual Studio 2008 through plugins (something similar to IronPython Studio). What can be done to achieve this? I look forward to suggestions.
对我来说一个有趣的选择是通过插件(类似于IronPython Studio 的东西)将cpython、Python 代码的单元测试和 Python 代码的代码覆盖率与 Visual Studio 2008集成。可以做些什么来实现这一目标?我期待着建议。
采纳答案by Kena
PyDev seems to allow code coverage from within Eclipse.
PyDev 似乎允许从 Eclipse 内部进行代码覆盖。
I've yet to find how to integrate that with my own (rather complex) build process, so I use Ned Batchelder's coverage.py at the command line.
我还没有找到如何将它与我自己的(相当复杂的)构建过程集成,所以我在命令行中使用了 Ned Batchelder 的coverage.py。
回答by Tony Arkles
We use this Django coverage integration, but instead of using the default coverage.py reporting, we generate some simple HTML: Colorize Python source using the built-in tokenizer.
我们使用这个Django 覆盖集成,但是我们没有使用默认的 coverage.py 报告,而是生成一些简单的 HTML: 使用内置的标记器着色 Python 源代码。
回答by Tor Norbye
NetBeans' new Python support has tightly integrated code coverage support - more info here.
NetBeans 的新 Python 支持紧密集成了代码覆盖支持 -更多信息请点击此处。
回答by davidavr
There is also figleafwhich I think is based on Ned Batchelder's coverage.py. We use noseas the driver for the testing. It all works pretty well. We write our unit tests using the built-in unittest and doctest modules.
还有云南黑籽,我认为是基于斯内德尔德的coverage.py。我们使用鼻子作为测试的驱动程序。这一切都很好。我们使用内置的 unittest 和 doctest 模块编写单元测试。
回答by RikkiVernon
If you want interactive code coverage, where you can see your coverage stats change in real time, take a look at Python Coverage Validator.
如果您想要交互式代码覆盖率,您可以在其中实时查看覆盖率统计数据的变化,请查看Python Coverage Validator。