Skip to content

Instantly share code, notes, and snippets.

@mscook
Created September 4, 2014 01:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mscook/ee692d836e68c5cc1243 to your computer and use it in GitHub Desktop.
Save mscook/ee692d836e68c5cc1243 to your computer and use it in GitHub Desktop.
wrapt examples!
##############################################################################
#
# Handling arguments
#
# This is a wrapt decorator equivalent to Colton Meyers' skipIf presented
# from about the 15 minute mark in his PyCon 2014 talk
#
##############################################################################
import wrapt
def skipIf(conditional, message):
@wrapt.decorator()
def wrapper(wrapped, instance, args, kwargs):
print "Checking if we need to execute..."
if not conditional:
return wrapped(*args, **kwargs)
else:
print message
return wrapper
@skipIf(False, "Skipped")
def func1():
print "Executing: func1"
@skipIf(True, "Skipped")
def func2():
print "Executing: func2"
func1()
func2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment