Created
February 5, 2018 11:14
-
-
Save jonashaag/b33151384d4138a9ce8545847e4e2eed to your computer and use it in GitHub Desktop.
Python subTest decorator
This file contains hidden or 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
| def subTests(params): | |
| """ | |
| @subTests(...) | |
| def test_foo(self): | |
| ... | |
| -> | |
| def test_foo(self): | |
| for param in ...: | |
| with self.subTest(param): | |
| ... | |
| """ | |
| def decorator(method): | |
| def wrapper(self, *args, **kwargs): | |
| for param in params: | |
| with self.subTest(param): | |
| method(*((self, param) + args), **kwargs) | |
| return wrapper | |
| return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment