How to use _get_test_list_file method in tempest

Best Python code snippet using tempest_python

test_run.py

Source:test_run.py Github

copy

Full Screen

...78 shutil.copy('tempest/tests/files/__init__.py', self.init_file)79 # Change directory, run wrapper and check result80 self.addCleanup(os.chdir, os.path.abspath(os.curdir))81 os.chdir(self.directory)82 def _get_test_list_file(self, content):83 fd, path = tempfile.mkstemp()84 self.addCleanup(os.remove, path)85 test_file = os.fdopen(fd, 'wb', 0)86 self.addCleanup(test_file.close)87 test_file.write(content.encode('utf-8'))88 return path89 def assertRunExit(self, cmd, expected):90 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,91 stderr=subprocess.PIPE)92 out, err = p.communicate()93 msg = ("Running %s got an unexpected returncode\n"94 "Stdout: %s\nStderr: %s" % (' '.join(cmd), out, err))95 self.assertEqual(p.returncode, expected, msg)96 return out, err97 def test_tempest_run_passes(self):98 self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)99 def test_tempest_run_passes_with_stestr_repository(self):100 subprocess.call(['stestr', 'init'])101 self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)102 def test_tempest_run_failing(self):103 self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1)104 def test_tempest_run_failing_with_stestr_repository(self):105 subprocess.call(['stestr', 'init'])106 self.assertRunExit(['tempest', 'run', '--regex', 'failing'], 1)107 def test_tempest_run_exclude_regex_failing(self):108 self.assertRunExit(['tempest', 'run',109 self.exclude_regex, 'failing'], 0)110 def test_tempest_run_exclude_regex_failing_with_stestr_repository(self):111 subprocess.call(['stestr', 'init'])112 self.assertRunExit(['tempest', 'run',113 self.exclude_regex, 'failing'], 0)114 def test_tempest_run_exclude_regex_passing(self):115 self.assertRunExit(['tempest', 'run',116 self.exclude_regex, 'passing'], 1)117 def test_tempest_run_exclude_regex_passing_with_stestr_repository(self):118 subprocess.call(['stestr', 'init'])119 self.assertRunExit(['tempest', 'run',120 self.exclude_regex, 'passing'], 1)121 def test_tempest_run_fails(self):122 self.assertRunExit(['tempest', 'run'], 1)123 def test_run_list(self):124 subprocess.call(['stestr', 'init'])125 out, err = self.assertRunExit(['tempest', 'run', '-l'], 0)126 tests = out.split()127 tests = sorted([str(x.rstrip()) for x in tests if x])128 result = [129 str('tests.test_failing.FakeTestClass.test_pass'),130 str('tests.test_failing.FakeTestClass.test_pass_list'),131 str('tests.test_passing.FakeTestClass.test_pass'),132 str('tests.test_passing.FakeTestClass.test_pass_list'),133 ]134 # NOTE(mtreinish): on python 3 the subprocess prints b'' around135 # stdout.136 result = ["b\'" + x + "\'" for x in result]137 self.assertEqual(result, tests)138 def test_tempest_run_with_worker_file(self):139 path = self._get_test_list_file(140 '- worker:\n - passing\n concurrency: 3')141 self.assertRunExit(['tempest', 'run', '--worker-file=%s' % path], 0)142 def test_tempest_run_with_include_list(self):143 path = self._get_test_list_file('passing')144 self.assertRunExit(['tempest', 'run',145 '%s=%s' % (self.include_list, path)], 0)146 def test_tempest_run_with_include_regex_include_pass_check_fail(self):147 path = self._get_test_list_file('passing')148 self.assertRunExit(['tempest', 'run',149 '%s=%s' % (self.include_list, path),150 '--regex', 'fail'], 1)151 def test_tempest_run_with_include_regex_include_pass_check_pass(self):152 path = self._get_test_list_file('passing')153 self.assertRunExit(['tempest', 'run',154 '%s=%s' % (self.include_list, path),155 '--regex', 'passing'], 0)156 def test_tempest_run_with_include_regex_include_fail_check_pass(self):157 path = self._get_test_list_file('failing')158 self.assertRunExit(['tempest', 'run',159 '%s=%s' % (self.include_list, path),160 '--regex', 'pass'], 1)161 def test_tempest_run_passes_with_config_file(self):162 self.assertRunExit(['tempest', 'run',163 '--config-file', self.stestr_conf_file,164 '--regex', 'passing'], 0)165 def test_tempest_run_with_exclude_list_failing(self):166 path = self._get_test_list_file('failing')167 self.assertRunExit(['tempest', 'run',168 '%s=%s' % (self.exclude_list, path)], 0)169 def test_tempest_run_with_exclude_list_passing(self):170 path = self._get_test_list_file('passing')171 self.assertRunExit(['tempest', 'run',172 '%s=%s' % (self.exclude_list, path)], 1)173 def test_tempest_run_with_exclude_list_regex_exclude_fail_check_pass(self):174 path = self._get_test_list_file('failing')175 self.assertRunExit(['tempest', 'run',176 '%s=%s' % (self.exclude_list, path),177 '--regex', 'pass'], 0)178 def test_tempest_run_with_exclude_list_regex_exclude_pass_check_pass(self):179 path = self._get_test_list_file('passing')180 self.assertRunExit(['tempest', 'run',181 '%s=%s' % (self.exclude_list, path),182 '--regex', 'pass'], 1)183 def test_tempest_run_with_exclude_list_regex_exclude_pass_check_fail(self):184 path = self._get_test_list_file('passing')185 self.assertRunExit(['tempest', 'run',186 '%s=%s' % (self.exclude_list, path),187 '--regex', 'fail'], 1)188class TestOldArgRunReturnCode(TestRunReturnCode):189 """A class for testing deprecated but still supported args.190 This class will be removed once we remove the following arguments:191 * --black-regex192 * --blacklist-file193 * --whitelist-file194 """195 exclude_regex = '--black-regex'196 exclude_list = '--blacklist-file'197 include_list = '--whitelist-file'198 def _test_args_passing(self, args):199 self.assertRunExit(['tempest', 'run'] + args, 0)200 def test_tempest_run_new_old_arg_comb(self):201 path = self._get_test_list_file('failing')202 self._test_args_passing(['--black-regex', 'failing',203 '--exclude-regex', 'failing'])204 self._test_args_passing(['--blacklist-file=' + path,205 '--exclude-list=' + path])206 path = self._get_test_list_file('passing')207 self._test_args_passing(['--whitelist-file=' + path,208 '--include-list=' + path])209 def _test_args_passing_with_stestr_repository(self, args):210 subprocess.call(['stestr', 'init'])211 self.assertRunExit(['tempest', 'run'] + args, 0)212 def test_tempest_run_new_old_arg_comb_with_stestr_repository(self):213 path = self._get_test_list_file('failing')214 self._test_args_passing_with_stestr_repository(215 ['--black-regex', 'failing', '--exclude-regex', 'failing'])216 self._test_args_passing_with_stestr_repository(217 ['--blacklist-file=' + path, '--exclude-list=' + path])218 path = self._get_test_list_file('passing')219 self._test_args_passing_with_stestr_repository(220 ['--whitelist-file=' + path, '--include-list=' + path])221class TestConfigPathCheck(base.TestCase):222 def setUp(self):223 super(TestConfigPathCheck, self).setUp()224 self.run_cmd = run.TempestRun(None, None)225 def test_tempest_run_set_config_path(self):226 # Note: (mbindlish) This test is created for the bug id: 1783751227 # Checking TEMPEST_CONFIG_DIR and TEMPEST_CONFIG is actually228 # getting set in os environment when some data has passed to229 # set the environment.230 _, path = tempfile.mkstemp()231 self.addCleanup(os.remove, path)232 self.run_cmd._set_env(path)...

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