在类中使用@attr的Python代码
我正在研究 open-stack 的 Tempest 代码。我看到在一个类里面使用了一个符号 @,像下面这样。有人能给我一个合适的链接,让我了解一下这个 @ 是用来干嘛的吗?
@classmethod
def setUpClass(cls):
cls.set_network_resources()
super(TestLargeOpsScenario, cls).setUpClass()
或者像这样,
@attr(type='smoke')
def test_update_setver_name(self):
name = rand_server('server')
那么这里的 @ 是有什么用呢?
2 个回答
0
@attr,装饰器设计模式(Decorator DP)。
想要更好地理解装饰器设计模式,可以参考以下例子:
http://thecodeship.com/patterns/guide-to-python-function-decorators/