什么是python中的禁用装饰器?

时间:2013-12-10 10:07:26

标签: python decorator python-decorators

当我正在阅读一些python代码时,我看到了以下内容:

@disabled
class IterCases(BaseMatchCase):

很难找到'禁用'装饰者的意思。看起来“不”禁用类本身,因为它在运行时被主动使用。

1 个答案:

答案 0 :(得分:3)

我找到了您正在查看的exact source code

该装饰器在oftest.testutils module中定义为:

def disabled(cls):
    """
    Testcase decorator that marks the test as being disabled.
    These tests are not automatically added to the "standard" group or
    their module's group.
    """
    cls._disabled = True
    return cls

所以它所做的就是设置一个_disabled属性。我找到了load_test_modules() function然后使用此属性跳过_disabled设置为True的所有类。

乍一看,装饰器似乎用于任何基础类;实际测试用例类使用的类。