Skip to content

Instantly share code, notes, and snippets.

@igniteflow
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igniteflow/7847cf96dd57d4f7aecc to your computer and use it in GitHub Desktop.
Save igniteflow/7847cf96dd57d4f7aecc to your computer and use it in GitHub Desktop.
A class decorator to apply Gargoyle's @Switches decorator to all test cases in a class
import inspect
def decorate_all_tests_in_class(decorator, prefix='test_', **kwargs):
def decorate_the_class(cls):
for name, m in inspect.getmembers(cls, inspect.ismethod):
if name.startswith(prefix):
setattr(cls, name, decorator(**kwargs)(m))
return cls
return decorate_the_class
@decorate_all_tests_in_class(switches, my_switch=True)
class MyTestCase(TestCase):
def test_foo(self):
self.assertTrue(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment