Skip to content

Instantly share code, notes, and snippets.

@grrussel
Created January 31, 2011 10:11
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 grrussel/803854 to your computer and use it in GitHub Desktop.
Save grrussel/803854 to your computer and use it in GitHub Desktop.
Simple test runner for python unit tests
def test_function1():
# Do some test code
# return True on Pass, False on Fail
return True
def test_function2_EXPECTED_FAIL():
# Do some test (more) code
# return True on Pass, False on Fail
return False
def test_functionN():
# Do some test (more) code
# return True on Pass, False on Fail
return False
# Build a list of test functions to run
# as test cases
tests = [ test_function1
, test_function2_EXPECTED_FAIL
#, ...
, test_functionN
]
def main():
failed = []
# Invoke each test case in turn
for t in tests:
if not t():
# Can check names of test functions
# to detect expected fails
if t.__name__.endswith("_EXPECTED_FAIL"):
continue
# Record fails for later report
failed.append(t.__name__)
# Can stop on 1st fail if desired
# return 1
# Print the list of tests that failed, if any
for f in failed:
print "FAIL:",f
# Invoke the test runner
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment