Created
March 30, 2010 10:35
-
-
Save skriticos/348994 to your computer and use it in GitHub Desktop.
Python test runner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python test runner. Add more tests with the test_sequence list. | |
# This assumes that the project to be tested is two folders above (../..) | |
# POSIX only | |
import os | |
import sys | |
import shutil | |
NAME = "TEMPLATE" | |
test_sequence = [ | |
"foo", | |
] | |
# setup path variables | |
tc_path = os.path.dirname(os.path.abspath(__file__)) | |
src_path = os.sep.join(tc_path.split(os.sep)[:-2]) | |
test_path = os.path.join("/", "tmp", NAME + "_test") | |
# setup test environment | |
if not os.path.exists(test_path): | |
os.mkdir(test_path) | |
sys.path.insert(0, src_path) | |
os.environ["PYTHONPATH"] = src_path | |
os.putenv("PYTHONPATH", src_path) | |
# exit cleanup hook | |
def _exit(exitcode): | |
if os.path.exists(test_path): | |
shutil.rmtree(test_path) | |
sys.exit(exitcode) | |
def run(): | |
print "-" * 64 | |
print "Running testcases.." | |
print "-" * 64 | |
code = 0 | |
for test in test_sequence: | |
result = __import__("test_" + test).suite() | |
if result.errors or result.failures: | |
code = 1 | |
break | |
_exit(code) | |
if __name__ == "__main__": | |
run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example test-case. | |
# Importing from your project here will use the source files, not the installed ones. | |
# Add test<xy> methods and extend tests with xy to add test-cases. | |
import os | |
import sys | |
import unittest | |
class TestFoo(unittest.TestCase): | |
def setUp(self): | |
pass | |
def testBar(self): | |
"""Testcase: bar() | |
""" | |
def tearDown(self): | |
pass | |
def suite(): | |
tests = ["testBar"] | |
ts = unittest.TestSuite(map(TestFoo, tests)) | |
return unittest.TextTestRunner(verbosity=2).run(ts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment