blob: b487c3f8ddc1bd41b7cbf767b1d791c61a7f55e8 [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 Treinisha051c222016-05-23 15:48:22 -040024
25from tempest.cmd import run
Manik Bindlish087d4d02018-08-01 10:10:22 +000026from tempest.cmd import workspace
Manik Bindlish321c85c2018-07-30 06:48:24 +000027from tempest import config
Manik Bindlish087d4d02018-08-01 10:10:22 +000028from tempest.lib.common.utils import data_utils
Matthew Treinisha051c222016-05-23 15:48:22 -040029from tempest.tests import base
30
31DEVNULL = open(os.devnull, 'wb')
Divyansh Acharya1bc06aa2017-08-18 15:09:46 +000032atexit.register(DEVNULL.close)
Matthew Treinisha051c222016-05-23 15:48:22 -040033
Manik Bindlish321c85c2018-07-30 06:48:24 +000034CONF = config.CONF
35
Matthew Treinisha051c222016-05-23 15:48:22 -040036
37class TestTempestRun(base.TestCase):
38
39 def setUp(self):
40 super(TestTempestRun, self).setUp()
41 self.run_cmd = run.TempestRun(None, None)
42
Matthew Treinisha051c222016-05-23 15:48:22 -040043 def test__build_regex_default(self):
44 args = mock.Mock(spec=argparse.Namespace)
45 setattr(args, 'smoke', False)
46 setattr(args, 'regex', '')
zhufle1afe4e2019-06-28 17:43:01 +080047 self.assertIsNone(self.run_cmd._build_regex(args))
Matthew Treinisha051c222016-05-23 15:48:22 -040048
49 def test__build_regex_smoke(self):
50 args = mock.Mock(spec=argparse.Namespace)
51 setattr(args, "smoke", True)
52 setattr(args, 'regex', '')
Chandan Kumar8a4396e2017-09-15 12:18:10 +053053 self.assertEqual(['smoke'], self.run_cmd._build_regex(args))
Matthew Treinisha051c222016-05-23 15:48:22 -040054
55 def test__build_regex_regex(self):
56 args = mock.Mock(spec=argparse.Namespace)
57 setattr(args, 'smoke', False)
58 setattr(args, "regex", 'i_am_a_fun_little_regex')
Chandan Kumar8a4396e2017-09-15 12:18:10 +053059 self.assertEqual(['i_am_a_fun_little_regex'],
Matthew Treinisha051c222016-05-23 15:48:22 -040060 self.run_cmd._build_regex(args))
61
Manik Bindlish087d4d02018-08-01 10:10:22 +000062 def test__build_regex_smoke_regex(self):
63 args = mock.Mock(spec=argparse.Namespace)
64 setattr(args, "smoke", True)
65 setattr(args, 'regex', 'i_am_a_fun_little_regex')
66 self.assertEqual(['smoke'], self.run_cmd._build_regex(args))
67
Matthew Treinisha051c222016-05-23 15:48:22 -040068
69class TestRunReturnCode(base.TestCase):
Martin Kopecdc844232020-12-24 15:57:53 +000070
71 exclude_regex = '--exclude-regex'
72 exclude_list = '--exclude-list'
73 include_list = '--include-list'
74
Matthew Treinisha051c222016-05-23 15:48:22 -040075 def setUp(self):
76 super(TestRunReturnCode, self).setUp()
77 # Setup test dirs
78 self.directory = tempfile.mkdtemp(prefix='tempest-unit')
79 self.addCleanup(shutil.rmtree, self.directory)
80 self.test_dir = os.path.join(self.directory, 'tests')
81 os.mkdir(self.test_dir)
82 # Setup Test files
Chandan Kumar8a4396e2017-09-15 12:18:10 +053083 self.stestr_conf_file = os.path.join(self.directory, '.stestr.conf')
Matthew Treinisha051c222016-05-23 15:48:22 -040084 self.setup_cfg_file = os.path.join(self.directory, 'setup.cfg')
85 self.passing_file = os.path.join(self.test_dir, 'test_passing.py')
86 self.failing_file = os.path.join(self.test_dir, 'test_failing.py')
87 self.init_file = os.path.join(self.test_dir, '__init__.py')
88 self.setup_py = os.path.join(self.directory, 'setup.py')
Chandan Kumar8a4396e2017-09-15 12:18:10 +053089 shutil.copy('tempest/tests/files/testr-conf', self.stestr_conf_file)
Matthew Treinisha051c222016-05-23 15:48:22 -040090 shutil.copy('tempest/tests/files/passing-tests', self.passing_file)
91 shutil.copy('tempest/tests/files/failing-tests', self.failing_file)
92 shutil.copy('setup.py', self.setup_py)
93 shutil.copy('tempest/tests/files/setup.cfg', self.setup_cfg_file)
94 shutil.copy('tempest/tests/files/__init__.py', self.init_file)
95 # Change directory, run wrapper and check result
96 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
97 os.chdir(self.directory)
98
Martin Kopecdc844232020-12-24 15:57:53 +000099 def _get_test_list_file(self, content):
100 fd, path = tempfile.mkstemp()
101 self.addCleanup(os.remove, path)
102 test_file = os.fdopen(fd, 'wb', 0)
103 self.addCleanup(test_file.close)
104 test_file.write(content.encode('utf-8'))
105 return path
106
Matthew Treinisha051c222016-05-23 15:48:22 -0400107 def assertRunExit(self, cmd, expected):
108 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
109 stderr=subprocess.PIPE)
110 out, err = p.communicate()
111 msg = ("Running %s got an unexpected returncode\n"
112 "Stdout: %s\nStderr: %s" % (' '.join(cmd), out, err))
113 self.assertEqual(p.returncode, expected, msg)
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500114 return out, err
Matthew Treinisha051c222016-05-23 15:48:22 -0400115
116 def test_tempest_run_passes(self):
Matthew Treinisha051c222016-05-23 15:48:22 -0400117 self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)
118
Chandan Kumar8a4396e2017-09-15 12:18:10 +0530119 def test_tempest_run_passes_with_stestr_repository(self):
120 subprocess.call(['stestr', 'init'])
Masayuki Igawafe2fa002016-06-22 12:58:34 +0900121 self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)
122
Manik Bindlish71c82372019-01-29 10:52:27 +0000123 def test_tempest_run_failing(self):
124 self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1)
125
126 def test_tempest_run_failing_with_stestr_repository(self):
127 subprocess.call(['stestr', 'init'])
128 self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1)
129
Martin Kopecdc844232020-12-24 15:57:53 +0000130 def test_tempest_run_exclude_regex_failing(self):
131 self.assertRunExit(['tempest', 'run',
132 self.exclude_regex, 'failing'], 0)
Manik Bindlish71c82372019-01-29 10:52:27 +0000133
Martin Kopecdc844232020-12-24 15:57:53 +0000134 def test_tempest_run_exclude_regex_failing_with_stestr_repository(self):
Manik Bindlish71c82372019-01-29 10:52:27 +0000135 subprocess.call(['stestr', 'init'])
Martin Kopecdc844232020-12-24 15:57:53 +0000136 self.assertRunExit(['tempest', 'run',
137 self.exclude_regex, 'failing'], 0)
Manik Bindlish71c82372019-01-29 10:52:27 +0000138
Martin Kopecdc844232020-12-24 15:57:53 +0000139 def test_tempest_run_exclude_regex_passing(self):
140 self.assertRunExit(['tempest', 'run',
141 self.exclude_regex, 'passing'], 1)
Manik Bindlish71c82372019-01-29 10:52:27 +0000142
Martin Kopecdc844232020-12-24 15:57:53 +0000143 def test_tempest_run_exclude_regex_passing_with_stestr_repository(self):
Manik Bindlish71c82372019-01-29 10:52:27 +0000144 subprocess.call(['stestr', 'init'])
Martin Kopecdc844232020-12-24 15:57:53 +0000145 self.assertRunExit(['tempest', 'run',
146 self.exclude_regex, 'passing'], 1)
Manik Bindlish71c82372019-01-29 10:52:27 +0000147
Matthew Treinisha051c222016-05-23 15:48:22 -0400148 def test_tempest_run_fails(self):
Matthew Treinisha051c222016-05-23 15:48:22 -0400149 self.assertRunExit(['tempest', 'run'], 1)
Brant Knudson6a090f42016-10-13 12:51:49 -0500150
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500151 def test_run_list(self):
152 subprocess.call(['stestr', 'init'])
153 out, err = self.assertRunExit(['tempest', 'run', '-l'], 0)
154 tests = out.split()
likui19b70a32020-12-02 13:25:18 +0800155 tests = sorted([str(x.rstrip()) for x in tests if x])
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500156 result = [
likui19b70a32020-12-02 13:25:18 +0800157 str('tests.test_failing.FakeTestClass.test_pass'),
158 str('tests.test_failing.FakeTestClass.test_pass_list'),
159 str('tests.test_passing.FakeTestClass.test_pass'),
160 str('tests.test_passing.FakeTestClass.test_pass_list'),
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500161 ]
162 # NOTE(mtreinish): on python 3 the subprocess prints b'' around
163 # stdout.
likui7d91c872020-09-22 12:29:16 +0800164 result = ["b\'" + x + "\'" for x in result]
Matthew Treinishf9902ec2018-02-22 12:11:46 -0500165 self.assertEqual(result, tests)
166
Arx Cruzc06c3712020-02-20 11:03:52 +0100167 def test_tempest_run_with_worker_file(self):
Martin Kopecdc844232020-12-24 15:57:53 +0000168 path = self._get_test_list_file(
169 '- worker:\n - passing\n concurrency: 3')
Arx Cruzc06c3712020-02-20 11:03:52 +0100170 self.assertRunExit(['tempest', 'run', '--worker-file=%s' % path], 0)
171
Martin Kopecdc844232020-12-24 15:57:53 +0000172 def test_tempest_run_with_include_list(self):
173 path = self._get_test_list_file('passing')
174 self.assertRunExit(['tempest', 'run',
175 '%s=%s' % (self.include_list, path)], 0)
Matthew Treinish3c6b15d2018-02-22 11:37:52 -0500176
Martin Kopecdc844232020-12-24 15:57:53 +0000177 def test_tempest_run_with_include_regex_include_pass_check_fail(self):
178 path = self._get_test_list_file('passing')
179 self.assertRunExit(['tempest', 'run',
180 '%s=%s' % (self.include_list, path),
Matthew Treinish3c6b15d2018-02-22 11:37:52 -0500181 '--regex', 'fail'], 1)
182
Martin Kopecdc844232020-12-24 15:57:53 +0000183 def test_tempest_run_with_include_regex_include_pass_check_pass(self):
184 path = self._get_test_list_file('passing')
185 self.assertRunExit(['tempest', 'run',
186 '%s=%s' % (self.include_list, path),
Manik Bindlish5a276ea2019-01-29 07:43:52 +0000187 '--regex', 'passing'], 0)
188
Martin Kopecdc844232020-12-24 15:57:53 +0000189 def test_tempest_run_with_include_regex_include_fail_check_pass(self):
190 path = self._get_test_list_file('failing')
191 self.assertRunExit(['tempest', 'run',
192 '%s=%s' % (self.include_list, path),
Manik Bindlish5a276ea2019-01-29 07:43:52 +0000193 '--regex', 'pass'], 1)
194
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900195 def test_tempest_run_passes_with_config_file(self):
196 self.assertRunExit(['tempest', 'run',
197 '--config-file', self.stestr_conf_file,
198 '--regex', 'passing'], 0)
199
Martin Kopecdc844232020-12-24 15:57:53 +0000200 def test_tempest_run_with_exclude_list_failing(self):
201 path = self._get_test_list_file('failing')
202 self.assertRunExit(['tempest', 'run',
203 '%s=%s' % (self.exclude_list, path)], 0)
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000204
Martin Kopecdc844232020-12-24 15:57:53 +0000205 def test_tempest_run_with_exclude_list_passing(self):
206 path = self._get_test_list_file('passing')
207 self.assertRunExit(['tempest', 'run',
208 '%s=%s' % (self.exclude_list, path)], 1)
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000209
Martin Kopecdc844232020-12-24 15:57:53 +0000210 def test_tempest_run_with_exclude_list_regex_exclude_fail_check_pass(self):
211 path = self._get_test_list_file('failing')
212 self.assertRunExit(['tempest', 'run',
213 '%s=%s' % (self.exclude_list, path),
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000214 '--regex', 'pass'], 0)
215
Martin Kopecdc844232020-12-24 15:57:53 +0000216 def test_tempest_run_with_exclude_list_regex_exclude_pass_check_pass(self):
217 path = self._get_test_list_file('passing')
218 self.assertRunExit(['tempest', 'run',
219 '%s=%s' % (self.exclude_list, path),
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000220 '--regex', 'pass'], 1)
221
Martin Kopecdc844232020-12-24 15:57:53 +0000222 def test_tempest_run_with_exclude_list_regex_exclude_pass_check_fail(self):
223 path = self._get_test_list_file('passing')
224 self.assertRunExit(['tempest', 'run',
225 '%s=%s' % (self.exclude_list, path),
Manik Bindlish9334ddb2019-01-29 10:26:43 +0000226 '--regex', 'fail'], 1)
227
melanie witt0b330af2023-12-07 01:44:40 +0000228 def test_tempest_run_with_slowest(self):
229 out, err = self.assertRunExit(['tempest', 'run', '--regex', 'passing',
230 '--slowest'], 0)
231 self.assertRegex(str(out), r'Test id\s+Runtime \(s\)')
232
Brant Knudson6a090f42016-10-13 12:51:49 -0500233
Martin Kopecdc844232020-12-24 15:57:53 +0000234class TestOldArgRunReturnCode(TestRunReturnCode):
235 """A class for testing deprecated but still supported args.
236
237 This class will be removed once we remove the following arguments:
238 * --black-regex
239 * --blacklist-file
240 * --whitelist-file
241 """
242 exclude_regex = '--black-regex'
243 exclude_list = '--blacklist-file'
244 include_list = '--whitelist-file'
245
246 def _test_args_passing(self, args):
247 self.assertRunExit(['tempest', 'run'] + args, 0)
248
249 def test_tempest_run_new_old_arg_comb(self):
250 path = self._get_test_list_file('failing')
251 self._test_args_passing(['--black-regex', 'failing',
252 '--exclude-regex', 'failing'])
253 self._test_args_passing(['--blacklist-file=' + path,
254 '--exclude-list=' + path])
255 path = self._get_test_list_file('passing')
256 self._test_args_passing(['--whitelist-file=' + path,
257 '--include-list=' + path])
258
259 def _test_args_passing_with_stestr_repository(self, args):
260 subprocess.call(['stestr', 'init'])
261 self.assertRunExit(['tempest', 'run'] + args, 0)
262
263 def test_tempest_run_new_old_arg_comb_with_stestr_repository(self):
264 path = self._get_test_list_file('failing')
265 self._test_args_passing_with_stestr_repository(
266 ['--black-regex', 'failing', '--exclude-regex', 'failing'])
267 self._test_args_passing_with_stestr_repository(
268 ['--blacklist-file=' + path, '--exclude-list=' + path])
269 path = self._get_test_list_file('passing')
270 self._test_args_passing_with_stestr_repository(
271 ['--whitelist-file=' + path, '--include-list=' + path])
272
273
Manik Bindlish321c85c2018-07-30 06:48:24 +0000274class TestConfigPathCheck(base.TestCase):
275 def setUp(self):
276 super(TestConfigPathCheck, self).setUp()
277 self.run_cmd = run.TempestRun(None, None)
278
279 def test_tempest_run_set_config_path(self):
280 # Note: (mbindlish) This test is created for the bug id: 1783751
281 # Checking TEMPEST_CONFIG_DIR and TEMPEST_CONFIG is actually
282 # getting set in os environment when some data has passed to
283 # set the environment.
284
Manik Bindlish21491df2018-12-14 06:58:42 +0000285 _, path = tempfile.mkstemp()
286 self.addCleanup(os.remove, path)
Manik Bindlish321c85c2018-07-30 06:48:24 +0000287
Manik Bindlish21491df2018-12-14 06:58:42 +0000288 self.run_cmd._set_env(path)
289 self.assertEqual(path, CONF._path)
290 self.assertIn('TEMPEST_CONFIG_DIR', os.environ)
291 self.assertEqual(path, os.path.join(os.environ['TEMPEST_CONFIG_DIR'],
292 os.environ['TEMPEST_CONFIG']))
293
294 def test_tempest_run_set_config_no_exist_path(self):
295 path = "fake/path"
296 self.assertRaisesRegex(FileNotFoundError,
297 'Config file: .* doesn\'t exist',
298 self.run_cmd._set_env, path)
299
300 def test_tempest_run_no_config_path(self):
Manik Bindlish321c85c2018-07-30 06:48:24 +0000301 # Note: (mbindlish) This test is created for the bug id: 1783751
302 # Checking TEMPEST_CONFIG_DIR and TEMPEST_CONFIG should have no value
303 # in os environment when no data has passed to set the environment.
304
305 self.run_cmd._set_env("")
306 self.assertFalse(CONF._path)
307 self.assertNotIn('TEMPEST_CONFIG_DIR', os.environ)
308 self.assertNotIn('TEMPEST_CONFIG', os.environ)
309
310
Brant Knudson6a090f42016-10-13 12:51:49 -0500311class TestTakeAction(base.TestCase):
Manik Bindlish087d4d02018-08-01 10:10:22 +0000312 def setUp(self):
313 super(TestTakeAction, self).setUp()
314 self.name = data_utils.rand_name('workspace')
315 self.path = tempfile.mkdtemp()
316 self.addCleanup(shutil.rmtree, self.path, ignore_errors=True)
317 store_dir = tempfile.mkdtemp()
318 self.addCleanup(shutil.rmtree, store_dir, ignore_errors=True)
319 self.store_file = os.path.join(store_dir, 'workspace.yaml')
320 self.workspace_manager = workspace.WorkspaceManager(
321 path=self.store_file)
322 self.workspace_manager.register_new_workspace(self.name, self.path)
323
324 def _setup_test_dirs(self):
325 self.directory = tempfile.mkdtemp(prefix='tempest-unit')
326 self.addCleanup(shutil.rmtree, self.directory, ignore_errors=True)
327 self.test_dir = os.path.join(self.directory, 'tests')
328 os.mkdir(self.test_dir)
329 # Change directory, run wrapper and check result
330 self.addCleanup(os.chdir, os.path.abspath(os.curdir))
331 os.chdir(self.directory)
332
Brant Knudson6a090f42016-10-13 12:51:49 -0500333 def test_workspace_not_registered(self):
334 class Exception_(Exception):
335 pass
336
337 m_exit = self.useFixture(fixtures.MockPatch('sys.exit')).mock
338 # sys.exit must not continue (or exit)
339 m_exit.side_effect = Exception_
340
341 workspace = self.getUniqueString()
342
343 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
344 parsed_args = mock.Mock()
345 parsed_args.config_file = []
346
347 # Override $HOME so that empty workspace gets created in temp dir.
348 self.useFixture(fixtures.TempHomeDir())
349
350 # Force use of the temporary home directory.
351 parsed_args.workspace_path = None
352
353 # Simulate --workspace argument.
354 parsed_args.workspace = workspace
355
356 self.assertRaises(Exception_, tempest_run.take_action, parsed_args)
357 exit_msg = m_exit.call_args[0][0]
358 self.assertIn(workspace, exit_msg)
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900359
360 def test_config_file_specified(self):
Manik Bindlish087d4d02018-08-01 10:10:22 +0000361 self._setup_test_dirs()
Manik Bindlish21491df2018-12-14 06:58:42 +0000362 _, path = tempfile.mkstemp()
363 self.addCleanup(os.remove, path)
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900364 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
365 parsed_args = mock.Mock()
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900366
367 parsed_args.workspace = None
368 parsed_args.state = None
369 parsed_args.list_tests = False
Manik Bindlish21491df2018-12-14 06:58:42 +0000370 parsed_args.config_file = path
melanie witt0b330af2023-12-07 01:44:40 +0000371 parsed_args.slowest = False
Masayuki Igawaff07eac2018-02-22 16:53:09 +0900372
373 with mock.patch('stestr.commands.run_command') as m:
374 m.return_value = 0
375 self.assertEqual(0, tempest_run.take_action(parsed_args))
376 m.assert_called()
Manik Bindlish087d4d02018-08-01 10:10:22 +0000377
378 def test_no_config_file_no_workspace_no_state(self):
379 self._setup_test_dirs()
380 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
381 parsed_args = mock.Mock()
382
383 parsed_args.workspace = None
384 parsed_args.state = None
385 parsed_args.list_tests = False
386 parsed_args.config_file = ''
387
388 with mock.patch('stestr.commands.run_command'):
389 self.assertRaises(SystemExit, tempest_run.take_action, parsed_args)
390
391 def test_config_file_workspace_registered(self):
392 self._setup_test_dirs()
Manik Bindlish21491df2018-12-14 06:58:42 +0000393 _, path = tempfile.mkstemp()
394 self.addCleanup(os.remove, path)
Manik Bindlish087d4d02018-08-01 10:10:22 +0000395 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
396 parsed_args = mock.Mock()
397 parsed_args.workspace = self.name
398 parsed_args.workspace_path = self.store_file
399 parsed_args.state = None
400 parsed_args.list_tests = False
Manik Bindlish21491df2018-12-14 06:58:42 +0000401 parsed_args.config_file = path
melanie witt0b330af2023-12-07 01:44:40 +0000402 parsed_args.slowest = False
Manik Bindlish087d4d02018-08-01 10:10:22 +0000403
404 with mock.patch('stestr.commands.run_command') as m:
405 m.return_value = 0
406 self.assertEqual(0, tempest_run.take_action(parsed_args))
407 m.assert_called()
408
409 @mock.patch('tempest.cmd.run.TempestRun._init_state')
410 def test_workspace_registered_no_config_no_state(self, mock_init_state):
411 self._setup_test_dirs()
412 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
413 parsed_args = mock.Mock()
414 parsed_args.workspace = self.name
415 parsed_args.workspace_path = self.store_file
416 parsed_args.state = None
417 parsed_args.list_tests = False
418 parsed_args.config_file = ''
melanie witt0b330af2023-12-07 01:44:40 +0000419 parsed_args.slowest = False
Manik Bindlish087d4d02018-08-01 10:10:22 +0000420
421 with mock.patch('stestr.commands.run_command') as m:
422 m.return_value = 0
423 self.assertEqual(0, tempest_run.take_action(parsed_args))
424 m.assert_called()
425 mock_init_state.assert_not_called()
426
427 @mock.patch('tempest.cmd.run.TempestRun._init_state')
428 def test_no_config_file_no_workspace_state_true(self, mock_init_state):
429 self._setup_test_dirs()
430 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
431 parsed_args = mock.Mock()
432
433 parsed_args.workspace = None
434 parsed_args.state = True
435 parsed_args.list_tests = False
436 parsed_args.config_file = ''
437
438 with mock.patch('stestr.commands.run_command'):
439 self.assertRaises(SystemExit, tempest_run.take_action, parsed_args)
440 mock_init_state.assert_not_called()
441
442 @mock.patch('tempest.cmd.run.TempestRun._init_state')
443 def test_workspace_registered_no_config_state_true(self, mock_init_state):
444 self._setup_test_dirs()
445 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
446 parsed_args = mock.Mock()
447 parsed_args.workspace = self.name
448 parsed_args.workspace_path = self.store_file
449 parsed_args.state = True
450 parsed_args.list_tests = False
451 parsed_args.config_file = ''
melanie witt0b330af2023-12-07 01:44:40 +0000452 parsed_args.slowest = False
Manik Bindlish087d4d02018-08-01 10:10:22 +0000453
454 with mock.patch('stestr.commands.run_command') as m:
455 m.return_value = 0
456 self.assertEqual(0, tempest_run.take_action(parsed_args))
457 m.assert_called()
458 mock_init_state.assert_called()
459
460 @mock.patch('tempest.cmd.run.TempestRun._init_state')
461 def test_no_workspace_config_file_state_true(self, mock_init_state):
462 self._setup_test_dirs()
Manik Bindlish21491df2018-12-14 06:58:42 +0000463 _, path = tempfile.mkstemp()
464 self.addCleanup(os.remove, path)
Manik Bindlish087d4d02018-08-01 10:10:22 +0000465 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())
466 parsed_args = mock.Mock()
467 parsed_args.workspace = None
468 parsed_args.workspace_path = self.store_file
469 parsed_args.state = True
470 parsed_args.list_tests = False
Manik Bindlish21491df2018-12-14 06:58:42 +0000471 parsed_args.config_file = path
melanie witt0b330af2023-12-07 01:44:40 +0000472 parsed_args.slowest = False
Manik Bindlish087d4d02018-08-01 10:10:22 +0000473
474 with mock.patch('stestr.commands.run_command') as m:
475 m.return_value = 0
476 self.assertEqual(0, tempest_run.take_action(parsed_args))
477 m.assert_called()
478 mock_init_state.assert_called()