Disable individual Python unit tests temporarily

后端 未结 7 817
臣服心动
臣服心动 2020-12-23 08:35

How can individual unit tests be temporarily disabled when using the unittest module in Python?

7条回答
  •  自闭症患者
    2020-12-23 09:09

    You can use decorators to disable the test that can wrap the function and prevent the googletest or python unit test to run the testcase.

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

    Output:

    testFoo has been disabled
    

提交回复
热议问题