jwg*_*jwg 11 python unit-testing nose
该nose
发现过程找到他的名字开头的所有模块test
,并在他们里面有所有功能test
的名称,并试图运行它们的单元测试.见http://nose.readthedocs.org/en/latest/man.html
我make_test_account
在文件中有一个名字的函数accounts.py
.我想在一个名为test的测试模块中测试该函数test_account
.所以在那个文件的开头我做了:
from foo.accounts import make_test_account
Run Code Online (Sandbox Code Playgroud)
但现在我发现nose将该函数make_test_account
视为单元测试并尝试运行它(失败因为它不传递任何参数,这是必需的).
如何确保鼻子忽略该功能?我宁愿这样做,这意味着我可以调用鼻子nosetests
,没有任何命令行参数.
Duš*_*ďar 10
告诉鼻子该功能不是测试 - 使用nottest
装饰器.
# module foo.accounts
from nose.tools import nottest
@nottest
def make_test_account():
...
Run Code Online (Sandbox Code Playgroud)
jsn*_*now 10
鼻子有一个nottest
装饰.但是,如果您不想@nottest
在要导入的模块中应用装饰器,也可以在导入后简单地修改方法.将单元测试逻辑保持在单元测试本身附近可能更清晰.
from foo.accounts import make_test_account
# prevent nose test from running this imported method
make_test_account.__test__ = False
Run Code Online (Sandbox Code Playgroud)
你仍然可以使用,nottest
但它具有相同的效果:
from nose.tools import nottest
from foo.accounts import make_test_account
# prevent nose test from running this imported method
make_test_account = nottest(make_test_account)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2271 次 |
最近记录: |