用鼻子禁用了一个示例测试

disabled one example test with nose

有没有办法告诉 nose 不要测试包含在包含其他需要测试的函数的文件中的特定函数 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

    '''

最佳

您可以提高 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()
    ...