Fixing the unit test suite. Tests were failing because they were being
passed unexpected command line arguments. Also, some tests were failing
because they were creating and destroying test databases with the same
name.
Risk: low
Visibility: medium
Signed-off-by: James Ren <jamesren@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1964 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/utils/unittest_suite.py b/utils/unittest_suite.py
index 5ff0fb1..e020545 100644
--- a/utils/unittest_suite.py
+++ b/utils/unittest_suite.py
@@ -23,6 +23,27 @@
'frontend_unittest.py',
))
+DEPENDENCIES = {
+ # Annotate dependencies here. The format is
+ # module: [list of modules on which it is dependent]
+ # (All modules in the list must run before this module can)
+
+ # Note: Do not make a short test dependent on a long one. This will cause
+ # the suite to fail if it is run without the --full flag, since the module
+ # that the short test depends on will not be run.
+
+
+ # The next two dependencies are not really dependencies. This is actually a
+ # hack to keep these three modules from running at the same time, since they
+ # all create and destroy a database with the same name.
+ 'autotest_lib.frontend.frontend_unittest':
+ ['autotest_lib.migrate.migrate_unittest'],
+
+ 'autotest_lib.scheduler.monitor_db_unittest':
+ ['autotest_lib.frontend.frontend_unittest',
+ 'autotest_lib.migrate.migrate_unittest'],
+}
+
modules = []
@@ -54,14 +75,22 @@
def run_tests(start, full=False):
os.path.walk(start, lister, full)
- functions = []
+ functions = {}
+ names_to_functions = {}
for module in modules:
# Create a function that'll test a particular module. module=module
# is a hack to force python to evaluate the params now. We then
# rename the function to make error reporting nicer.
run_module = lambda module=module: run_test(module)
- run_module.__name__ = '.'.join(module)
- functions.append(run_module)
+ name = '.'.join(module)
+ run_module.__name__ = name
+ names_to_functions[name] = run_module
+ functions[run_module] = set()
+
+ for fn, deps in DEPENDENCIES.iteritems():
+ if fn in names_to_functions:
+ functions[names_to_functions[fn]] = set(
+ names_to_functions[dep] for dep in deps)
try:
dargs = {}
@@ -81,6 +110,10 @@
parser.print_help()
sys.exit(1)
+ # Strip the arguments off the command line, so that the unit tests do not
+ # see them.
+ sys.argv = [sys.argv[0]]
+
errors = run_tests(os.path.join(root, options.start), options.full)
if errors:
print "%d tests resulted in an error/failure:" % len(errors)