提交 d36e9bc3 编写于 作者: C Cleber Rosa 提交者: Amador Pahim

Job phases: introduce run_tests

The run_tests phase is responsible for actually running the test suite
that has been created in the create_test_suite phase.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 c3ae6559
......@@ -428,7 +428,36 @@ class Job(object):
"""
self.create_test_suite()
self.pre_tests()
return self.run_tests()
def create_test_suite(self):
"""
Creates the test suite for this Job
This is a public Job API as part of the documented Job phases
"""
if (getattr(self.args, 'remote_hostname', False) and
getattr(self.args, 'remote_no_copy', False)):
self.test_suite = [(None, {})]
else:
try:
self.test_suite = self._make_test_suite(self.urls)
except loader.LoaderError as details:
stacktrace.log_exc_info(sys.exc_info(), 'avocado.app.debug')
raise exceptions.OptionValidationError(details)
def pre_tests(self):
"""
Run the pre tests execution hooks
By default this runs the plugins that implement the
:class:`avocado.core.plugin_interfaces.JobPre` interface.
"""
self._job_pre_post_dispatcher = dispatcher.JobPrePostDispatcher()
output.log_plugin_failures(self._job_pre_post_dispatcher.load_failures)
self._job_pre_post_dispatcher.map_method('pre', self)
def run_tests(self):
if not self.test_suite:
if self.urls:
e_msg = ("No tests found for given urls, try 'avocado list -V "
......@@ -480,33 +509,6 @@ class Job(object):
return self.exitcode
def create_test_suite(self):
"""
Creates the test suite for this Job
This is a public Job API as part of the documented Job phases
"""
if (getattr(self.args, 'remote_hostname', False) and
getattr(self.args, 'remote_no_copy', False)):
self.test_suite = [(None, {})]
else:
try:
self.test_suite = self._make_test_suite(self.urls)
except loader.LoaderError as details:
stacktrace.log_exc_info(sys.exc_info(), 'avocado.app.debug')
raise exceptions.OptionValidationError(details)
def pre_tests(self):
"""
Run the pre tests execution hooks
By default this runs the plugins that implement the
:class:`avocado.core.plugin_interfaces.JobPre` interface.
"""
self._job_pre_post_dispatcher = dispatcher.JobPrePostDispatcher()
output.log_plugin_failures(self._job_pre_post_dispatcher.load_failures)
self._job_pre_post_dispatcher.map_method('pre', self)
def run(self):
"""
Handled main job method. Runs a list of test URLs to its completion.
......
......@@ -7,16 +7,16 @@ else:
from avocado.core import test
from avocado.core import job
from avocado.core import exit_codes
from avocado.utils import path as utils_path
class JobTest(unittest.TestCase):
@staticmethod
def _find_simple_test_candidates():
simple_test_candidates = ['true', 'time', 'uptime']
def _find_simple_test_candidates(candidates=['true', 'time', 'uptime']):
found = []
for candidate in simple_test_candidates:
for candidate in candidates:
try:
found.append(utils_path.find_command(candidate))
except utils_path.CmdNotFoundError:
......@@ -68,5 +68,13 @@ class JobTest(unittest.TestCase):
myjob.pre_tests()
self.assertLessEqual(len(myjob.test_suite), 1)
def test_job_run_tests(self):
simple_tests_found = self._find_simple_test_candidates(['true'])
args = argparse.Namespace(url=simple_tests_found)
myjob = job.Job(args)
myjob.create_test_suite()
self.assertEqual(myjob.run_tests(),
exit_codes.AVOCADO_ALL_OK)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册