禁用Python单元测试并附带消息
我用的Python版本不支持
@unittest.skip("demonstrating skipping")
来自 暂时禁用单个Python单元测试,我知道怎么用装饰器来实现这个功能,也就是
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()
1 个回答
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()