-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()
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Peaceful
  • 472
  • 5
  • 13

1 Answers1

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()
SoylentFuchsia
  • 1,181
  • 9
  • 8