Skip to content

Instantly share code, notes, and snippets.

@bootandy
Created February 6, 2013 18:18
Show Gist options
  • Save bootandy/4724593 to your computer and use it in GitHub Desktop.
Save bootandy/4724593 to your computer and use it in GitHub Desktop.
python. monkey patch a celery method so we can test it
class TestEmailer(unittest.TestCase):
def setUp(self):
super(TestEmailer, self).setUp()
self.applied_tasks = []
self.original_celery = celery_jobs.post_url.delay
def new_apply_async(*args):
self.applied_tasks.append(args)
# monkey patch my celery job function
celery_jobs.post_url.delay = new_apply_async
def tearDown(self):
super(TestEmailer, self).tearDown()
# Reset the monkey patch to the original method
celery_jobs.post_url.delay = self.original_celery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment