Last active
August 29, 2015 14:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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