有没有办法告诉鼻子不要测试包含在需要测试的其他函数的文件中的特定函数foo()?
def foo():
'''Was the function does.
:Example:
>>> # I don't wan't to test this code
>>> # because it uses imports
>>> # of some packages not declared as dependencies
'''
最佳
答案 0 :(得分:2)
您可以提出SkipTest:
from nose.plugins.skip import SkipTest
def test_that_only_works_when_certain_module_is_available():
if module is not available:
raise SkipTest("Test %s is skipped" % func.__name__)
或使用unittest.skip装饰器:
import unittest
@unittest.skip("temporarily disabled")
class MyTestCase(unittest.TestCase):
...
或者,如果这甚至不是测试功能,但被错误地检测为测试功能,并且您不希望该功能在测试报告中显示为已跳过测试,则可以将其标记为nottest装饰器:>
from nose.tools import nottest
@nottest
def test_but_not_really_test()
...