Best Python code snippet using tempest_python
test_run.py
Source:test_run.py
...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):...
test_return_codes.py
Source:test_return_codes.py
...44 self.stderr = StringIO()45 # Change directory, run wrapper and check result46 self.addCleanup(os.chdir, os.path.abspath(os.curdir))47 os.chdir(self.directory)48 def assertRunExit(self, cmd, expected, subunit=False):49 p = subprocess.Popen(50 "%s" % cmd, shell=True,51 stdout=subprocess.PIPE, stderr=subprocess.PIPE)52 out, err = p.communicate()53 if not subunit:54 self.assertEqual(55 p.returncode, expected,56 "Stdout: %s; Stderr: %s" % (out, err))57 else:58 self.assertEqual(p.returncode, expected,59 "Expected return code: %s doesn't match actual "60 "return code of: %s" % (expected, p.returncode))61 def test_default_passing(self):62 self.assertRunExit('ostestr --regex passing', 0)63 def test_default_fails(self):64 self.assertRunExit('ostestr', 1)65 def test_default_passing_no_slowest(self):66 self.assertRunExit('ostestr --no-slowest --regex passing', 0)67 def test_default_fails_no_slowest(self):68 self.assertRunExit('ostestr --no-slowest', 1)69 def test_default_serial_passing(self):70 self.assertRunExit('ostestr --serial --regex passing', 0)71 def test_default_serial_fails(self):72 self.assertRunExit('ostestr --serial', 1)73 def test_testr_subunit_passing(self):74 self.assertRunExit('ostestr --no-pretty --subunit --regex passing', 0,75 subunit=True)76 @testtools.skip('Skipped because of testrepository lp bug #1411804')77 def test_testr_subunit_fails(self):78 self.assertRunExit('ostestr --no-pretty --subunit', 1, subunit=True)79 def test_testr_no_pretty_passing(self):80 self.assertRunExit('ostestr --no-pretty --regex passing', 0)81 def test_testr_no_pretty_fails(self):82 self.assertRunExit('ostestr --no-pretty', 1)83 def test_list(self):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!