-1

My version of Python does not support

    @unittest.skip("demonstrating skipping")

from Disable individual Python unit tests temporarily, I understand how to use a decorator to achieve this, i.e.,

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

However, the decorator does not support providing a message for the skipping. May I know how I can achieve this please? I basically want something like

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 Answer 1

0

You can modify the decorator like so:

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.