diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-06-28 20:27:18 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-06-28 20:27:18 +0100 |
commit | 44aa220f4965df14c4b88032646f4025a3ebfd20 (patch) | |
tree | db8c30e052a2c79f8f1e218aab299428c931e823 | |
parent | fc92a206b0a95dec76875fff47b7cb8e08b4628f (diff) | |
download | systest-44aa220f4965df14c4b88032646f4025a3ebfd20.tar.gz |
Load tests from filenames, not Python module names.
This makes it more userfriendly: systest tests/*.py
-rwxr-xr-x | systest | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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() |