对于nose中的装饰器make_decorator的理解

来源:互联网 发布:美国历史书籍推荐知乎 编辑:程序博客网 时间:2024/06/13 22:12
          nose.tools.make_decorator(func)

Wraps a test decorator so as to properly replicate metadata of the decorated function, including nose’s additional stuff (namely, setup and teardown)





from nose.tools import make_decorator, with_setup

def setup_func():
    print "setup"




def teardown_func():
    print "teardown"




@with_setup(setup_func, teardown_func)
def test1():
    pass




@make_decorator(test1)
def test2():
    pass




运行的结果如下:setupteardown.setupteardown.----------------------------------------------------------------------Ran 2 tests in 0.005sOK分析:从运行结果中可以看到,使用make_decorator(test1)来装饰test2后test2也有了setup和teardown的效果;从开头引用文档的字面意思解释:使用make_decorator()使得test2是复制了test1的metadata只是我不是特别清楚,metadata具体包含哪些内容呢?一时之间也没能找到权威的解释,如有朋友了解,请不吝赐教!