Skip to content

Instantly share code, notes, and snippets.

@coolcodr
Created July 14, 2012 08:48
Show Gist options
  • Save coolcodr/3110083 to your computer and use it in GitHub Desktop.
Save coolcodr/3110083 to your computer and use it in GitHub Desktop.
A Python decorator, @Assume, it will skip the test if the condition argument is False. It works similar to org.junit.Assume.assumeTrue().
from nose.tools import nottest, istest
class assume(object):
def __init__(self, bool_condition):
self.bool_condition = bool_condition
def __call__(self, test_func):
if not self.bool_condition:
return nottest(test_func)
else:
return istest(test_func)
import unittest
from django.conf import settings
class IntegrationTest(unittest.TestCase):
@assume(hasattr(settings, 'INTEGRATION_TEST_ENABLED') and settings.INTEGRATION_TEST_ENABLED)
def test_something(self):
# dome some tests here
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment