Skip to content

Instantly share code, notes, and snippets.

@sigilioso
Last active December 21, 2015 01:39
Show Gist options
  • Save sigilioso/6229199 to your computer and use it in GitHub Desktop.
Save sigilioso/6229199 to your computer and use it in GitHub Desktop.
An example to provide assert function from unittest.TestCase
from unittest import TestCase
import inspect
class AssertExample(object):
def __create_method(self, tc, name):
def method(self, *args, **kwargs):
return tc.__getattribute__(name)(self, *args, **kwargs)
return method
def __init__(self):
tc = TestCase('__init__')
for name, method in inspect.getmembers(tc):
if name.startswith('assert'):
self.__setattr__(name, self.__create_method(tc, name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment