How to use _setup_test_dirs method in tempest

Best Python code snippet using tempest_python

test_run.py

Source:test_run.py Github

copy

Full Screen

...239 self.store_file = os.path.join(store_dir, 'workspace.yaml')240 self.workspace_manager = workspace.WorkspaceManager(241 path=self.store_file)242 self.workspace_manager.register_new_workspace(self.name, self.path)243 def _setup_test_dirs(self):244 self.directory = tempfile.mkdtemp(prefix='tempest-unit')245 self.addCleanup(shutil.rmtree, self.directory, ignore_errors=True)246 self.test_dir = os.path.join(self.directory, 'tests')247 os.mkdir(self.test_dir)248 # Change directory, run wrapper and check result249 self.addCleanup(os.chdir, os.path.abspath(os.curdir))250 os.chdir(self.directory)251 def test_workspace_not_registered(self):252 class Exception_(Exception):253 pass254 m_exit = self.useFixture(fixtures.MockPatch('sys.exit')).mock255 # sys.exit must not continue (or exit)256 m_exit.side_effect = Exception_257 workspace = self.getUniqueString()258 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())259 parsed_args = mock.Mock()260 parsed_args.config_file = []261 # Override $HOME so that empty workspace gets created in temp dir.262 self.useFixture(fixtures.TempHomeDir())263 # Force use of the temporary home directory.264 parsed_args.workspace_path = None265 # Simulate --workspace argument.266 parsed_args.workspace = workspace267 self.assertRaises(Exception_, tempest_run.take_action, parsed_args)268 exit_msg = m_exit.call_args[0][0]269 self.assertIn(workspace, exit_msg)270 def test_config_file_specified(self):271 self._setup_test_dirs()272 _, path = tempfile.mkstemp()273 self.addCleanup(os.remove, path)274 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())275 parsed_args = mock.Mock()276 parsed_args.workspace = None277 parsed_args.state = None278 parsed_args.list_tests = False279 parsed_args.config_file = path280 with mock.patch('stestr.commands.run_command') as m:281 m.return_value = 0282 self.assertEqual(0, tempest_run.take_action(parsed_args))283 m.assert_called()284 def test_no_config_file_no_workspace_no_state(self):285 self._setup_test_dirs()286 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())287 parsed_args = mock.Mock()288 parsed_args.workspace = None289 parsed_args.state = None290 parsed_args.list_tests = False291 parsed_args.config_file = ''292 with mock.patch('stestr.commands.run_command'):293 self.assertRaises(SystemExit, tempest_run.take_action, parsed_args)294 def test_config_file_workspace_registered(self):295 self._setup_test_dirs()296 _, path = tempfile.mkstemp()297 self.addCleanup(os.remove, path)298 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())299 parsed_args = mock.Mock()300 parsed_args.workspace = self.name301 parsed_args.workspace_path = self.store_file302 parsed_args.state = None303 parsed_args.list_tests = False304 parsed_args.config_file = path305 with mock.patch('stestr.commands.run_command') as m:306 m.return_value = 0307 self.assertEqual(0, tempest_run.take_action(parsed_args))308 m.assert_called()309 @mock.patch('tempest.cmd.run.TempestRun._init_state')310 def test_workspace_registered_no_config_no_state(self, mock_init_state):311 self._setup_test_dirs()312 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())313 parsed_args = mock.Mock()314 parsed_args.workspace = self.name315 parsed_args.workspace_path = self.store_file316 parsed_args.state = None317 parsed_args.list_tests = False318 parsed_args.config_file = ''319 with mock.patch('stestr.commands.run_command') as m:320 m.return_value = 0321 self.assertEqual(0, tempest_run.take_action(parsed_args))322 m.assert_called()323 mock_init_state.assert_not_called()324 @mock.patch('tempest.cmd.run.TempestRun._init_state')325 def test_no_config_file_no_workspace_state_true(self, mock_init_state):326 self._setup_test_dirs()327 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())328 parsed_args = mock.Mock()329 parsed_args.workspace = None330 parsed_args.state = True331 parsed_args.list_tests = False332 parsed_args.config_file = ''333 with mock.patch('stestr.commands.run_command'):334 self.assertRaises(SystemExit, tempest_run.take_action, parsed_args)335 mock_init_state.assert_not_called()336 @mock.patch('tempest.cmd.run.TempestRun._init_state')337 def test_workspace_registered_no_config_state_true(self, mock_init_state):338 self._setup_test_dirs()339 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())340 parsed_args = mock.Mock()341 parsed_args.workspace = self.name342 parsed_args.workspace_path = self.store_file343 parsed_args.state = True344 parsed_args.list_tests = False345 parsed_args.config_file = ''346 with mock.patch('stestr.commands.run_command') as m:347 m.return_value = 0348 self.assertEqual(0, tempest_run.take_action(parsed_args))349 m.assert_called()350 mock_init_state.assert_called()351 @mock.patch('tempest.cmd.run.TempestRun._init_state')352 def test_no_workspace_config_file_state_true(self, mock_init_state):353 self._setup_test_dirs()354 _, path = tempfile.mkstemp()355 self.addCleanup(os.remove, path)356 tempest_run = run.TempestRun(app=mock.Mock(), app_args=mock.Mock())357 parsed_args = mock.Mock()358 parsed_args.workspace = None359 parsed_args.workspace_path = self.store_file360 parsed_args.state = True361 parsed_args.list_tests = False362 parsed_args.config_file = path363 with mock.patch('stestr.commands.run_command') as m:364 m.return_value = 0365 self.assertEqual(0, tempest_run.take_action(parsed_args))366 m.assert_called()367 mock_init_state.assert_called()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful