avocado: Introduce handling of non existent tests

When tests don't exist, current avocado breaks on
a very spectacular fashion:

Traceback (most recent call last):
  File "scripts/avocado", line 29, in <module>
    sys.exit(app.run())
  File "/home/lmr/Code/avocado2/avocado/cli/app.py", line 72, in run
    return self.args.func(self.args)
  File "/home/lmr/Code/avocado2/avocado/plugins/runner.py", line 106, in
run_tests
    return job_instance.run()
  File "/home/lmr/Code/avocado2/avocado/job.py", line 111, in run
    test_instance = self.run_test(url)
  File "/home/lmr/Code/avocado2/avocado/job.py", line 76, in run_test
    test_instance = self._load_test_instance(url)
  File "/home/lmr/Code/avocado2/avocado/job.py", line 63, in
_load_test_instance
    f, p, d = imp.find_module(url, [test_module_dir])
ImportError: No module named bogustest

We should be of course more classy when such a problem happens.
Introduce a NonExistentTest class to handle such problems,
and use it when the ImportError happens. The end result is
a lot better:

DEBUG LOG: /home/lmr/avocado/logs/run-2014-04-29-13.12.34/debug.log
TOTAL TESTS: 1
(1/1) bogustest.1:  ERROR (0.10 s)
TOTAL PASSED: 0
TOTAL ERROR: 1
TOTAL FAILED: 0
TOTAL SKIPPED: 0
TOTAL WARNED: 0
ELAPSED TIME: 0.10 s
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 902f3bd9
......@@ -59,14 +59,18 @@ class Job(object):
base_logdir=self.debugdir,
job=self)
else:
test_module_dir = os.path.join(self.test_dir, url)
f, p, d = imp.find_module(url, [test_module_dir])
test_module = imp.load_module(url, f, p, d)
f.close()
test_class = getattr(test_module, url)
test_instance = test_class(name=url,
base_logdir=self.debugdir,
job=self)
try:
test_module_dir = os.path.join(self.test_dir, url)
f, p, d = imp.find_module(url, [test_module_dir])
test_module = imp.load_module(url, f, p, d)
f.close()
test_class = getattr(test_module, url)
except ImportError:
test_class = test.MissingTest
finally:
test_instance = test_class(name=url,
base_logdir=self.debugdir,
job=self)
return test_instance
def run_test(self, url):
......
......@@ -294,3 +294,20 @@ class DropinTest(Test):
except exceptions.CmdError, details:
self._log_detailed_cmd_info(details.result)
raise exceptions.TestFail(details)
class MissingTest(Test):
"""
Handle when there is no such test module in the test directory.
"""
def __init__(self, name=None, base_logdir=None, tag=None, job=None):
super(MissingTest, self).__init__(name=name,
base_logdir=base_logdir,
tag=tag, job=job)
def action(self):
raise exceptions.TestError('Test %s could not be found in the test '
'dir %s' %
(self.name, data_dir.get_test_dir()))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册