From 2adb67d38e49e166658d9e996fb4869bc7a69a86 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 11 Mar 2016 23:04:02 -0800 Subject: [PATCH] runtests: remove .py extension, only run tests when ran as a script --- runtests | 26 ++++++++++++++++++++++++++ runtests.py | 24 ------------------------ 2 files changed, 26 insertions(+), 24 deletions(-) create mode 100755 runtests delete mode 100755 runtests.py diff --git a/runtests b/runtests new file mode 100755 index 0000000..87c37e4 --- /dev/null +++ b/runtests @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import unittest +import glob +import os +import sys + +if __name__ == '__main__': + + runner = unittest.TextTestRunner(verbosity=2) + fails = [] + suites = [] + + # Yay, import hacks! + sys.path.append(os.path.join(os.getcwd(), 'tests')) + + query = sys.argv[1:] or glob.glob('tests/test_*.py') + + for testfile in query: + # Strip the tests/ and .py extension: tests/test_whatever.py => test_whatever + module = testfile.replace('.py', '').replace('tests/', '') + module = __import__(module) + suites.append(unittest.defaultTestLoader.loadTestsFromModule(module)) + + testsuite = unittest.TestSuite(suites) + runner.run(testsuite) diff --git a/runtests.py b/runtests.py deleted file mode 100755 index b4d7996..0000000 --- a/runtests.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 - -import unittest -import glob -import os -import sys - -runner = unittest.TextTestRunner(verbosity=2) -fails = [] -suites = [] - -# Yay, import hacks! -sys.path.append(os.path.join(os.getcwd(), 'tests')) - -query = sys.argv[1:] or glob.glob('tests/test_*.py') - -for testfile in query: - # Strip the tests/ and .py extension: tests/test_whatever.py => test_whatever - module = testfile.replace('.py', '').replace('tests/', '') - module = __import__(module) - suites.append(unittest.defaultTestLoader.loadTestsFromModule(module)) - -testsuite = unittest.TestSuite(suites) -runner.run(testsuite)