Skip to content

Instantly share code, notes, and snippets.

@inactivist
Last active September 29, 2020 01:33
Show Gist options
  • Save inactivist/8b7795fe5922e20083d68cadf72dc390 to your computer and use it in GitHub Desktop.
Save inactivist/8b7795fe5922e20083d68cadf72dc390 to your computer and use it in GitHub Desktop.
Helper function to find and run all functions prefixed with test_* in current module
def run_all_tests():
# pytest would be nicer
import types
for name, member in globals().items(): # NB: not iteritems()
if isinstance(member, types.FunctionType) and name.startswith("test_"):
print("Run test:", member.__name__)
member()
if __name__ == "__main__":
run_all_tests()
print("*** All tests pass ***")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment