2014-02-27 51 views
-1

我的Python版本不從 Disable individual Python unit tests temporarily支持禁用蟒蛇單元測試與消息

@unittest.skip("demonstrating skipping") 

,我知道如何使用一個裝飾來實現這一點,即

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() 

然而,裝飾者不支持爲跳過提供消息。我可以知道我該怎麼做到這一點嗎?我想basiacally像

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

您可以修改裝飾,像這樣:

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()