Getting nose to ignore a function with 'test' in the name

只谈情不闲聊 提交于 2019-11-30 18:19:23

Nose has a nottest decorator. However, if you don't want to apply the @nottest decorator in the module you are importing from you can also simply modify the method after the import. It may be cleaner to keep unit test logic close to the unit test itself.

from foo.accounts import make_test_account
# prevent nose test from running this imported method
make_test_account.__test__ = False

You can still use nottest but it has the same effect:

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)

Tell nose that the function is not a test - use the nottest decorator.

# module foo.accounts

from nose.tools import nottest

@nottest
def make_test_account():
    ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!