Skip to content

Instantly share code, notes, and snippets.

@not-much-io
Created February 18, 2016 11:36
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 not-much-io/5f0bed606996fea9c410 to your computer and use it in GitHub Desktop.
Save not-much-io/5f0bed606996fea9c410 to your computer and use it in GitHub Desktop.
def get_tests(test_case_class):
"""Gets all tests from a TestCase class.
:param test_case_class: A subclass of TestCase
:return: tests in the TestCase
"""
test_case_instance = eval(test_case_class.__name__ + "()")
func_type = type(lambda x: None)
test_methods = []
for name in test_case_class.__dict__:
if name.startswith("test"):
call_expr = test_case_instance.__class__.__name__ + "." + name
data_type = type(eval(call_expr))
if data_type == func_type:
test_methods.append(test_case_class(name))
return test_methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment