Skip to content

Instantly share code, notes, and snippets.

@jonashaag
Created February 5, 2018 11:14
Show Gist options
  • Select an option

  • Save jonashaag/b33151384d4138a9ce8545847e4e2eed to your computer and use it in GitHub Desktop.

Select an option

Save jonashaag/b33151384d4138a9ce8545847e4e2eed to your computer and use it in GitHub Desktop.
Python subTest decorator
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