我正在尝试争论 Nose +覆盖范围。如果我有这个代码:
class Foobar(object):
def add(self, a, b):
return a + b
这个测试:
from unittest import TestCase
from foobar import Foobar
class FoobarTest(TestCase):
def test_good(self):
f = Foobar()
self.assertEquals(f.add(1,2), 3)
那么一切看起来都很好!
$ nosetests
.
Name Stmts Miss Cover Missing
-----------------------------------------
foobar.py 3 0 100%
----------------------------------------------------------------------
Ran 1 test in 0.018s
OK
但是如果我在源代码中添加一行
import requests
class Foobar(object):
def add(self, a, b):
return a + b
然后我的报告中会得到很多额外的内容
$ nosetests
.
Name Stmts Miss Cover Missing
--------------------------------------------------------------------------------------------------------
foobar.py 4 0 100%
requests.py 26 5 81% 54, 72-75
requests/adapters.py 180 134 26% 48, 51, 54, 89-102, 105, 111-117, 1
[snip]
那么我如何配置覆盖范围以表示“不必费心测量或报告属于我的 virtualenv 一部分的任何内容 - 只需在我的工作目录下执行这些操作即可”。我确信它与 .coveragerc 有关,但我在正确调用时遇到了一些问题。
最佳答案
想通了。
1) 删除任何与覆盖率相关的 ini 文件
2)将其添加到“nose.cfg”在你的主目录中作为 Nose 的东西
[nosetests]
with-coverage=1 ; generate a coverage report (in the "cover" directory)
cover-package=. ; only report on coverage files in the current directory
cover-html=1 ; generate a pretty html report
cover-erase=1 ; re-generate coverage statistics on each run
当然,您必须确保您的测试文件与 Nose 正在寻找的 testMatch 模式匹配。
关于nosetests - 如何告诉 Nose 和覆盖范围不要在我的 virtualenv 中包含文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33150637/