blob: ec7b76092ef37632d05bf38da40381f787573137 [file] [log] [blame]
Matthew Treinisha051c222016-05-23 15:48:22 -04001# Copyright 2015 Hewlett-Packard Development Company, L.P.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import argparse
Divyansh Acharya1bc06aa2017-08-18 15:09:46 +000016import atexit
Matthew Treinisha051c222016-05-23 15:48:22 -040017import os
18import shutil
19import subprocess
20import tempfile
Sean McGinniseed80742020-04-18 12:01:03 -050021from unittest import mock
Matthew Treinisha051c222016-05-23 15:48:22 -040022
Brant Knudson6a090f42016-10-13 12:51:49 -050023import fixtures
Matthew Treinishf9902ec2018-02-22 12:11:46 -050024import six
Matthew Treinisha051c222016-05-23 15:48:22 -040025
26from tempest.cmd import run
Manik Bindlish087d4d02018-08-01 10:10:22 +000027from tempest.cmd import workspace
Manik Bindlish321c85c2018-07-30 06:48:24 +000028from tempest import config
Manik Bindlish087d4d02018-08-01 10:10:22 +000029from tempest.lib.common.utils import data_utils
Matthew Treinisha051c222016-05-23 15:48:22 -040030from tempest.tests import base
31
32DEVNULL = open(os.devnull, 'wb')
Divyansh Acharya1bc06aa2017-08-18 15:09:46 +000033atexit.register(DEVNULL.close)
Matthew Treinisha051c222016-05-23 15:48:22 -040034
Manik Bindlish321c85c2018-07-30 06:48:24 +000035CONF = config.CONF
36
Matthew Treinisha051c222016-05-23 15:48:22 -040037
38class TestTempestRun(base.TestCase):
39
40 def setUp(self):
41 super(TestTempestRun, self).setUp()
42 self.run_cmd = run.TempestRun(None, None)
43
Matthew Treinisha051c222016-05-23 15:48:22 -040044 def test__build_regex_default(self):
45 args = mock.Mock(spec=argparse.Namespace)
46 setattr(args, 'smoke', False)
47 setattr(args, 'regex', '')
zhufle1afe4e2019-06-28 17:43:01 +080048 self.assertIsNone(self.run_cmd._build_regex(args))
Matthew Treinisha051c222016-05-23 15:48:22 -040049
50 def test__build_regex_smoke(self):
51 args = mock.Mock(spec=argparse.Namespace)
52 setattr(args, "smoke", True)
53 setattr(args, 'regex', '')
Chandan Kumar8a4396e2017-09-15 12:18:10 +053054 self.assertEqual(['smoke'], self.run_cmd._build_regex(args))
Matthew Treinisha051c222016-05-23 15:48:22 -040055
56 def test__build_regex_regex(self):
57 args = mock.Mock(spec=argparse.Namespace)
58 setattr(args, 'smoke', False)
59 setattr(args, "regex", 'i_am_a_fun_little_regex')
Chandan Kumar8a4396e2017-09-15 12:18:10 +053060 self.assertEqual(['i_am_a_fun_little_regex'],
Matthew Treinisha051c222016-05-23 15:48:22 -040061 self.run_cmd._build_regex(args))
62
Manik Bindlish087d4d02018-08-01 10:10:22 +000063 def test__build_regex_smoke_regex(self):
64 args = mock.Mock(spec=argparse.Namespace)
65 setattr(args, "smoke", True)
66 setattr(args, 'regex', 'i_am_a_fun_little_regex')
67 self.assertEqual(['smoke'], self.run_cmd._build_regex(args))
68
Matthew Treinisha051c222016-05-23 15:48:22 -040069
70class TestRunReturnCode(base.TestCase):
Martin Kopecdc844232020-12-24 15:57:53 +000071
72 exclude_regex = '--exclude-regex'
73 exclude_list = '--exclude-list'
74 include_list = '--include-list'
75
Matthew Treinisha051c222016-05-23 15:48:22 -040076 def setUp(self):
77 super(TestRunReturnCode, self).setUp()
78 # Setup test dirs
79 self.directory = tempfile.mkdtemp(prefix='tempest-unit')
80 self.addCleanup(shutil.rmtree, self.directory)
81 self.test_dir = os.path.join(self.directory, 'tests')
82 os.mkdir(self.test_dir)
83 # Setup Test files
Chandan Kumar8a4396e2017-09-15 12:18:10 +053084 self.stestr_conf_file = os.path.join(self.directory, '.stestr.conf')
Matthew Treinisha051c222016-05-23 15:48:22 -040085 self.setup_cfg_file = os.path.join(self.directory, 'setup.cfg')
86 self.passing_file = os.path.join(self.test_dir, 'test_passing.py')
87 self.failing_file = os.path.join(self.test_dir, 'test_failing.py')
88 self.init_file = os.path.join(self.test_dir, '__init__.py')
89 self.setup_py = os.path.join(self.directory, 'setup.py')
Chandan Kumar8a4396e2017-09-15 12:18:10 +053090 shutil.copy('tempest/tests/files/testr-conf', self.stestr_conf_file)
Matthew Treinisha051c222016-05-23 15:48:22 -040091 shutil.copy('tempest/tests/files/passing-tests', self.passing_file)
92 shutil.copy('tempest/tests/files/failing-tests', self.failing_file)
93 shutil.copy('setup.py', self.setup_py)
94 shutil.copy('tempest/tests/files/setup.cfg', self.setup_cfg_file)
95 shutil.copy('tempest/tests/files/__init__.py', self.init_file)
96 # Change directory, run wrapper and check result
97 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
98 os.chdir(self.directory)
99
Martin Kopecdc844232020-12-24 15:57:53 +0000100 def _get_test_list_file(self, content):
101 fd, path = tempfile.mkstemp()
102 self.addCleanup(os.remove, path)
103 test_file = os.fdopen(fd, 'wb', 0)
104 self.addCleanup(test_file.close)
105 test_file.write(content.encode('utf-8'))
106 return path
107
Matthew Treinisha051c222016-05-23 15:48:22 -0400108 def assertRunExit(self, cmd, expected):
109 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
110 stderr=subprocess.PIPE)
111 out, err = p.communicate()
112 msg = ("Running %s got an unexpected returncode\n"
113 "Stdout: %s\nStderr: %s" % (' '.join(cmd), out, err))
114 self.assertEqual(p.returncode, expected, msg)
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500115 return out, err
Matthew Treinisha051c222016-05-23 15:48:22 -0400116
117 def test_tempest_run_passes(self):
Matthew Treinisha051c222016-05-23 15:48:22 -0400118 self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)
119
Chandan Kumar8a4396e2017-09-15 12:18:10 +0530120 def test_tempest_run_passes_with_stestr_repository(self):
121 subprocess.call(['stestr', 'init'])
Masayuki Igawafe2fa002016-06-22 12:58:34 +0900122 self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)
123
Manik Bindlish71c82372019-01-29 10:52:27 +0000124 def test_tempest_run_failing(self):
125 self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1)
126
127 def test_tempest_run_failing_with_stestr_repository(self):
128 subprocess.call(['stestr', 'init'])
129 self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1)
130
Martin Kopecdc844232020-12-24 15:57:53 +0000131 def test_tempest_run_exclude_regex_failing(self):
132 self.assertRunExit(['tempest', 'run',
133 self.exclude_regex, 'failing'], 0)
Manik Bindlish71c82372019-01-29 10:52:27 +0000134
Martin Kopecdc844232020-12-24 15:57:53 +0000135 def test_tempest_run_exclude_regex_failing_with_stestr_repository(self):
Manik Bindlish71c82372019-01-29 10:52:27 +0000136 subprocess.call(['stestr', 'init'])
Martin Kopecdc844232020-12-24 15:57:53 +0000137 self.assertRunExit(['tempest', 'run',
138 self.exclude_regex, 'failing'], 0)
Manik Bindlish71c82372019-01-29 10:52:27 +0000139
Martin Kopecdc844232020-12-24 15:57:53 +0000140 def test_tempest_run_exclude_regex_passing(self):
141 self.assertRunExit(['tempest', 'run',
142 self.exclude_regex, 'passing'], 1)
Manik Bindlish71c82372019-01-29 10:52:27 +0000143
Martin Kopecdc844232020-12-24 15:57:53 +0000144 def test_tempest_run_exclude_regex_passing_with_stestr_repository(self):
Manik Bindlish71c82372019-01-29 10:52:27 +0000145 subprocess.call(['stestr', 'init'])
Martin Kopecdc844232020-12-24 15:57:53 +0000146 self.assertRunExit(['tempest', 'run',
147 self.exclude_regex, 'passing'], 1)
Manik Bindlish71c82372019-01-29 10:52:27 +0000148
Matthew Treinisha051c222016-05-23 15:48:22 -0400149 def test_tempest_run_fails(self):
Matthew Treinisha051c222016-05-23 15:48:22 -0400150 self.assertRunExit(['tempest', 'run'], 1)
Brant Knudson6a090f42016-10-13 12:51:49 -0500151
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500152 def test_run_list(self):
153 subprocess.call(['stestr', 'init'])
154 out, err = self.assertRunExit(['tempest', 'run', '-l'], 0)
155 tests = out.split()
156 tests = sorted([six.text_type(x.rstrip()) for x in tests if x])
157 result = [
158 six.text_type('tests.test_failing.FakeTestClass.test_pass'),
159 six.text_type('tests.test_failing.FakeTestClass.test_pass_list'),
160 six.text_type('tests.test_passing.FakeTestClass.test_pass'),
161 six.text_type('tests.test_passing.FakeTestClass.test_pass_list'),
162 ]
163 # NOTE(mtreinish): on python 3 the subprocess prints b'' around
164 # stdout.
likui7d91c872020-09-22 12:29:16 +0800165 result = ["b\'" + x + "\'" for x in result]
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500166 self.assertEqual(result, tests)
167
Arx Cruzc06c3712020-02-20 11:03:52 +0100168 def test_tempest_run_with_worker_file(self):
Martin Kopecdc844232020-12-24 15:57:53 +0000169 path = self._get_test_list_file(
170 '- worker:\n - passing\n concurrency: 3')
Arx Cruzc06c3712020-02-20 11:03:52 +0100171 self.assertRunExit(['tempest', 'run', '--worker-file=%s' % path], 0)
172
Martin Kopecdc844232020-12-24 15:57:53 +0000173 def test_tempest_run_with_include_list(self):
174 path = self._get_test_list_file('passing')
175 self.assertRunExit(['tempest', 'run',
176 '%s=%s' % (self.include_list, path)], 0)
Matthew Treinish3c6b15d2018-02-22 11:37:52 -0500177
Martin Kopecdc844232020-12-24 15:57:53 +0000178 def test_tempest_run_with_include_regex_include_pass_check_fail(self):
179 path = self._get_test_list_file('passing')
180 self.assertRunExit(['tempest', 'run',
181 '%s=%s' % (self.include_list, path),
Matthew Treinish3c6b15d2018-02-22 11:37:52 -0500182 '--regex', 'fail'], 1)
183
Martin Kopecdc844232020-12-24 15:57:53 +0000184 def test_tempest_run_with_include_regex_include_pass_check_pass(self):
185 path = self._get_test_list_file('passing')
186 self.assertRunExit(['tempest', 'run',
187 '%s=%s' % (self.include_list, path),
Manik Bindlish5a276ea2019-01-29 07:43:52 +0000188 '--regex', 'passing'], 0)
189
Martin Kopecdc844232020-12-24 15:57:53 +0000190 def test_tempest_run_with_include_regex_include_fail_check_pass(self):
191 path = self._get_test_list_file('failing')
192 self.assertRunExit(['tempest', 'run',
193 '%s=%s' % (self.include_list, path),
Manik Bindlish5a276ea2019-01-29 07:43:52 +0000194 '--regex', 'pass'], 1)
195
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900196 def test_tempest_run_passes_with_config_file(self):
197 self.assertRunExit(['tempest', 'run',
198 '--config-file', self.stestr_conf_file,
199 '--regex', 'passing'], 0)
200
Martin Kopecdc844232020-12-24 15:57:53 +0000201 def test_tempest_run_with_exclude_list_failing(self):
202 path = self._get_test_list_file('failing')
203 self.assertRunExit(['tempest', 'run',
204 '%s=%s' % (self.exclude_list, path)], 0)
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000205
Martin Kopecdc844232020-12-24 15:57:53 +0000206 def test_tempest_run_with_exclude_list_passing(self):
207 path = self._get_test_list_file('passing')
208 self.assertRunExit(['tempest', 'run',
209 '%s=%s' % (self.exclude_list, path)], 1)
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000210
Martin Kopecdc844232020-12-24 15:57:53 +0000211 def test_tempest_run_with_exclude_list_regex_exclude_fail_check_pass(self):
212 path = self._get_test_list_file('failing')
213 self.assertRunExit(['tempest', 'run',
214 '%s=%s' % (self.exclude_list, path),
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000215 '--regex', 'pass'], 0)
216
Martin Kopecdc844232020-12-24 15:57:53 +0000217 def test_tempest_run_with_exclude_list_regex_exclude_pass_check_pass(self):
218 path = self._get_test_list_file('passing')
219 self.assertRunExit(['tempest', 'run',
220 '%s=%s' % (self.exclude_list, path),
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000221 '--regex', 'pass'], 1)
222
Martin Kopecdc844232020-12-24 15:57:53 +0000223 def test_tempest_run_with_exclude_list_regex_exclude_pass_check_fail(self):
224 path = self._get_test_list_file('passing')
225 self.assertRunExit(['tempest', 'run',
226 '%s=%s' % (self.exclude_list, path),
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000227 '--regex', 'fail'], 1)
228
Brant Knudson6a090f42016-10-13 12:51:49 -0500229
Martin Kopecdc844232020-12-24 15:57:53 +0000230class TestOldArgRunReturnCode(TestRunReturnCode):
231 """A class for testing deprecated but still supported args.
232
233 This class will be removed once we remove the following arguments:
234 * --black-regex
235 * --blacklist-file
236 * --whitelist-file
237 """
238 exclude_regex = '--black-regex'
239 exclude_list = '--blacklist-file'
240 include_list = '--whitelist-file'
241
242 def _test_args_passing(self, args):
243 self.assertRunExit(['tempest', 'run'] + args, 0)
244
245 def test_tempest_run_new_old_arg_comb(self):
246 path = self._get_test_list_file('failing')
247 self._test_args_passing(['--black-regex', 'failing',
248 '--exclude-regex', 'failing'])
249 self._test_args_passing(['--blacklist-file=' + path,
250 '--exclude-list=' + path])
251 path = self._get_test_list_file('passing')
252 self._test_args_passing(['--whitelist-file=' + path,
253 '--include-list=' + path])
254
255 def _test_args_passing_with_stestr_repository(self, args):
256 subprocess.call(['stestr', 'init'])
257 self.assertRunExit(['tempest', 'run'] + args, 0)
258
259 def test_tempest_run_new_old_arg_comb_with_stestr_repository(self):
260 path = self._get_test_list_file('failing')
261 self._test_args_passing_with_stestr_repository(
262 ['--black-regex', 'failing', '--exclude-regex', 'failing'])
263 self._test_args_passing_with_stestr_repository(
264 ['--blacklist-file=' + path, '--exclude-list=' + path])
265 path = self._get_test_list_file('passing')
266 self._test_args_passing_with_stestr_repository(
267 ['--whitelist-file=' + path, '--include-list=' + path])
268
269
Manik Bindlish321c85c2018-07-30 06:48:24 +0000270class TestConfigPathCheck(base.TestCase):
271 def setUp(self):
272 super(TestConfigPathCheck, self).setUp()
273 self.run_cmd = run.TempestRun(None, None)
274
275 def test_tempest_run_set_config_path(self):
276 # Note: (mbindlish) This test is created for the bug id: 1783751
277 # Checking TEMPEST_CONFIG_DIR and TEMPEST_CONFIG is actually
278 # getting set in os environment when some data has passed to
279 # set the environment.
280
Manik Bindlish21491df2018-12-14 06:58:42 +0000281 _, path = tempfile.mkstemp()
282 self.addCleanup(os.remove, path)
Manik Bindlish321c85c2018-07-30 06:48:24 +0000283
Manik Bindlish21491df2018-12-14 06:58:42 +0000284 self.run_cmd._set_env(path)
285 self.assertEqual(path, CONF._path)
286 self.assertIn('TEMPEST_CONFIG_DIR', os.environ)
287 self.assertEqual(path, os.path.join(os.environ['TEMPEST_CONFIG_DIR'],
288 os.environ['TEMPEST_CONFIG']))
289
290 def test_tempest_run_set_config_no_exist_path(self):
291 path = "fake/path"
292 self.assertRaisesRegex(FileNotFoundError,
293 'Config file: .* doesn\'t exist',
294 self.run_cmd._set_env, path)
295
296 def test_tempest_run_no_config_path(self):
Manik Bindlish321c85c2018-07-30 06:48:24 +0000297 # Note: (mbindlish) This test is created for the bug id: 1783751
298 # Checking TEMPEST_CONFIG_DIR and TEMPEST_CONFIG should have no value
299 # in os environment when no data has passed to set the environment.
300
301 self.run_cmd._set_env("")
302 self.assertFalse(CONF._path)
303 self.assertNotIn('TEMPEST_CONFIG_DIR', os.environ)
304 self.assertNotIn('TEMPEST_CONFIG', os.environ)
305
306
Brant Knudson6a090f42016-10-13 12:51:49 -0500307class TestTakeAction(base.TestCase):
Manik Bindlish087d4d02018-08-01 10:10:22 +0000308 def setUp(self):
309 super(TestTakeAction, self).setUp()
310 self.name = data_utils.rand_name('workspace')
311 self.path = tempfile.mkdtemp()
312 self.addCleanup(shutil.rmtree, self.path, ignore_errors=True)
313 store_dir = tempfile.mkdtemp()
314 self.addCleanup(shutil.rmtree, store_dir, ignore_errors=True)
315 self.store_file = os.path.join(store_dir, 'workspace.yaml')
316 self.workspace_manager = workspace.WorkspaceManager(
317 path=self.store_file)
318 self.workspace_manager.register_new_workspace(self.name, self.path)
319
320 def _setup_test_dirs(self):
321 self.directory = tempfile.mkdtemp(prefix='tempest-unit')
322 self.addCleanup(shutil.rmtree, self.directory, ignore_errors=True)
323 self.test_dir = os.path.join(self.directory, 'tests')
324 os.mkdir(self.test_dir)
325 # Change directory, run wrapper and check result
326 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
327 os.chdir(self.directory)
328
Brant Knudson6a090f42016-10-13 12:51:49 -0500329 def test_workspace_not_registered(self):
330 class Exception_(Exception):
331 pass
332
333 m_exit = self.useFixture(fixtures.MockPatch('sys.exit')).mock
334 # sys.exit must not continue (or exit)
335 m_exit.side_effect = Exception_
336
337 workspace = self.getUniqueString()
338
339 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
340 parsed_args = mock.Mock()
341 parsed_args.config_file = []
342
343 # Override $HOME so that empty workspace gets created in temp dir.
344 self.useFixture(fixtures.TempHomeDir())
345
346 # Force use of the temporary home directory.
347 parsed_args.workspace_path = None
348
349 # Simulate --workspace argument.
350 parsed_args.workspace = workspace
351
352 self.assertRaises(Exception_, tempest_run.take_action, parsed_args)
353 exit_msg = m_exit.call_args[0][0]
354 self.assertIn(workspace, exit_msg)
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900355
356 def test_config_file_specified(self):
Manik Bindlish087d4d02018-08-01 10:10:22 +0000357 self._setup_test_dirs()
Manik Bindlish21491df2018-12-14 06:58:42 +0000358 _, path = tempfile.mkstemp()
359 self.addCleanup(os.remove, path)
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900360 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
361 parsed_args = mock.Mock()
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900362
363 parsed_args.workspace = None
364 parsed_args.state = None
365 parsed_args.list_tests = False
Manik Bindlish21491df2018-12-14 06:58:42 +0000366 parsed_args.config_file = path
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900367
368 with mock.patch('stestr.commands.run_command') as m:
369 m.return_value = 0
370 self.assertEqual(0, tempest_run.take_action(parsed_args))
371 m.assert_called()
Manik Bindlish087d4d02018-08-01 10:10:22 +0000372
373 def test_no_config_file_no_workspace_no_state(self):
374 self._setup_test_dirs()
375 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
376 parsed_args = mock.Mock()
377
378 parsed_args.workspace = None
379 parsed_args.state = None
380 parsed_args.list_tests = False
381 parsed_args.config_file = ''
382
383 with mock.patch('stestr.commands.run_command'):
384 self.assertRaises(SystemExit, tempest_run.take_action, parsed_args)
385
386 def test_config_file_workspace_registered(self):
387 self._setup_test_dirs()
Manik Bindlish21491df2018-12-14 06:58:42 +0000388 _, path = tempfile.mkstemp()
389 self.addCleanup(os.remove, path)
Manik Bindlish087d4d02018-08-01 10:10:22 +0000390 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
391 parsed_args = mock.Mock()
392 parsed_args.workspace = self.name
393 parsed_args.workspace_path = self.store_file
394 parsed_args.state = None
395 parsed_args.list_tests = False
Manik Bindlish21491df2018-12-14 06:58:42 +0000396 parsed_args.config_file = path
Manik Bindlish087d4d02018-08-01 10:10:22 +0000397
398 with mock.patch('stestr.commands.run_command') as m:
399 m.return_value = 0
400 self.assertEqual(0, tempest_run.take_action(parsed_args))
401 m.assert_called()
402
403 @mock.patch('tempest.cmd.run.TempestRun._init_state')
404 def test_workspace_registered_no_config_no_state(self, mock_init_state):
405 self._setup_test_dirs()
406 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
407 parsed_args = mock.Mock()
408 parsed_args.workspace = self.name
409 parsed_args.workspace_path = self.store_file
410 parsed_args.state = None
411 parsed_args.list_tests = False
412 parsed_args.config_file = ''
413
414 with mock.patch('stestr.commands.run_command') as m:
415 m.return_value = 0
416 self.assertEqual(0, tempest_run.take_action(parsed_args))
417 m.assert_called()
418 mock_init_state.assert_not_called()
419
420 @mock.patch('tempest.cmd.run.TempestRun._init_state')
421 def test_no_config_file_no_workspace_state_true(self, mock_init_state):
422 self._setup_test_dirs()
423 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
424 parsed_args = mock.Mock()
425
426 parsed_args.workspace = None
427 parsed_args.state = True
428 parsed_args.list_tests = False
429 parsed_args.config_file = ''
430
431 with mock.patch('stestr.commands.run_command'):
432 self.assertRaises(SystemExit, tempest_run.take_action, parsed_args)
433 mock_init_state.assert_not_called()
434
435 @mock.patch('tempest.cmd.run.TempestRun._init_state')
436 def test_workspace_registered_no_config_state_true(self, mock_init_state):
437 self._setup_test_dirs()
438 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
439 parsed_args = mock.Mock()
440 parsed_args.workspace = self.name
441 parsed_args.workspace_path = self.store_file
442 parsed_args.state = True
443 parsed_args.list_tests = False
444 parsed_args.config_file = ''
445
446 with mock.patch('stestr.commands.run_command') as m:
447 m.return_value = 0
448 self.assertEqual(0, tempest_run.take_action(parsed_args))
449 m.assert_called()
450 mock_init_state.assert_called()
451
452 @mock.patch('tempest.cmd.run.TempestRun._init_state')
453 def test_no_workspace_config_file_state_true(self, mock_init_state):
454 self._setup_test_dirs()
Manik Bindlish21491df2018-12-14 06:58:42 +0000455 _, path = tempfile.mkstemp()
456 self.addCleanup(os.remove, path)
Manik Bindlish087d4d02018-08-01 10:10:22 +0000457 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
458 parsed_args = mock.Mock()
459 parsed_args.workspace = None
460 parsed_args.workspace_path = self.store_file
461 parsed_args.state = True
462 parsed_args.list_tests = False
Manik Bindlish21491df2018-12-14 06:58:42 +0000463 parsed_args.config_file = path
Manik Bindlish087d4d02018-08-01 10:10:22 +0000464
465 with mock.patch('stestr.commands.run_command') as m:
466 m.return_value = 0
467 self.assertEqual(0, tempest_run.take_action(parsed_args))
468 m.assert_called()
469 mock_init_state.assert_called()