我的python版本不支持
@unittest.skip("demonstrating skipping")
这 Disable individual Python unit tests temporarily,我了解如何使用装饰器来实现这一点,即
def disabled(f):
def _decorator():
print f.__name__ + ' has been disabled'
return _decorator
@disabled
def testFoo():
'''Foo test case'''
print 'this is foo test case'
testFoo()
但是,装饰器不支持为跳过提供消息。我可以知道如何实现这一目标吗?我基本上想要像
这样的东西def disabled(f, msg):
def _decorator():
print f.__name__ + ' has been disabled' + msg
return _decorator
@disabled("I want to skip it")
def testFoo():
'''Foo test case'''
print 'this is foo test case'
testFoo()
答案 0 :(得分:0)
您可以像这样修改装饰器:
def disabled(msg):
def _decorator(f):
def _wrapper():
print f.__name__ + ' has been disabled ' + msg
return _wrapper
return _decorator
@disabled("I want to skip it")
def testFoo():
'''Foo test case'''
print 'this is foo test case'
testFoo()