From 44aa220f4965df14c4b88032646f4025a3ebfd20 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 28 Jun 2011 20:27:18 +0100 Subject: Load tests from filenames, not Python module names. This makes it more userfriendly: systest tests/*.py --- systest | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/systest b/systest index d6fed0c..0c35f2a 100755 --- a/systest +++ b/systest @@ -1,7 +1,9 @@ #!/usr/bin/python import cliapp +import imp import logging +import os import re import subprocess import unittest @@ -19,7 +21,10 @@ class SystemTest(cliapp.Application): def process_args(self, args): loader = unittest.defaultTestLoader loader.suiteClass = self.create_suite - suite = loader.loadTestsFromNames(args) + suite = unittest.TestSuite() + for filename in args: + module = self.load_module(filename) + suite.addTest(loader.loadTestsFromModule(module)) unittest.TextTestRunner().run(suite) def create_suite(self, tests): @@ -28,6 +33,15 @@ class SystemTest(cliapp.Application): suite = unittest.TestSuite(tests) return suite + def load_module(self, filename): + for t in imp.get_suffixes(): + suffix, mode, kind = t + if filename.endswith(suffix): + module_name = os.path.basename(filename[:-len(suffix)]) + with open(filename, mode) as f: + return imp.load_module(module_name, f, filename, t) + raise Exception("Unknown module: %s" % filename) + if __name__ == '__main__': SystemTest().run() -- cgit v1.2.1