Best Python code snippet using avocado_python
test_loader.py
Source:test_loader.py
...359 'avocado_loader_unittest',360 DEFAULT_NON_EXEC_MODE)361 with avocado_pass_test as test_script:362 test_suite = self.loader.discover(test_script.path, loader.DiscoverMode.ALL)363 self.assertEqual([], loader.filter_test_tags(test_suite, []))364 self.assertEqual(test_suite,365 loader.filter_test_tags(test_suite, [], True))366 def test_filter_tags(self):367 avocado_test_tags = script.TemporaryScript('tags.py',368 AVOCADO_TEST_TAGS,369 'avocado_loader_unittest',370 DEFAULT_NON_EXEC_MODE)371 with avocado_test_tags as test_script:372 test_suite = self.loader.discover(test_script.path, loader.DiscoverMode.ALL)373 self.assertEqual(len(test_suite), 5)374 self.assertEqual(test_suite[0][0], 'FastTest')375 self.assertEqual(test_suite[0][1]['methodName'], 'test_fast')376 self.assertEqual(test_suite[1][0], 'FastTest')377 self.assertEqual(test_suite[1][1]['methodName'], 'test_fast_other')378 self.assertEqual(test_suite[2][0], 'SlowTest')379 self.assertEqual(test_suite[2][1]['methodName'], 'test_slow')380 self.assertEqual(test_suite[3][0], 'SlowUnsafeTest')381 self.assertEqual(test_suite[3][1]['methodName'], 'test_slow_unsafe')382 self.assertEqual(test_suite[4][0], 'SafeTest')383 self.assertEqual(test_suite[4][1]['methodName'], 'test_safe')384 filtered = loader.filter_test_tags(test_suite, ['fast,net'])385 self.assertEqual(len(filtered), 2)386 self.assertEqual(filtered[0][0], 'FastTest')387 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')388 self.assertEqual(filtered[1][0], 'FastTest')389 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')390 filtered = loader.filter_test_tags(test_suite,391 ['fast,net',392 'slow,disk,unsafe'])393 self.assertEqual(len(filtered), 3)394 self.assertEqual(filtered[0][0], 'FastTest')395 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')396 self.assertEqual(filtered[1][0], 'FastTest')397 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')398 self.assertEqual(filtered[2][0], 'SlowUnsafeTest')399 self.assertEqual(filtered[2][1]['methodName'], 'test_slow_unsafe')400 filtered = loader.filter_test_tags(test_suite,401 ['fast,net',402 'slow,disk'])403 self.assertEqual(len(filtered), 4)404 self.assertEqual(filtered[0][0], 'FastTest')405 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')406 self.assertEqual(filtered[1][0], 'FastTest')407 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')408 self.assertEqual(filtered[2][0], 'SlowTest')409 self.assertEqual(filtered[2][1]['methodName'], 'test_slow')410 self.assertEqual(filtered[3][0], 'SlowUnsafeTest')411 self.assertEqual(filtered[3][1]['methodName'], 'test_slow_unsafe')412 filtered = loader.filter_test_tags(test_suite,413 ['-fast,-slow'])414 self.assertEqual(len(filtered), 1)415 self.assertEqual(filtered[0][0], 'SafeTest')416 self.assertEqual(filtered[0][1]['methodName'], 'test_safe')417 filtered = loader.filter_test_tags(test_suite,418 ['-fast,-slow,-safe'])419 self.assertEqual(len(filtered), 0)420 filtered = loader.filter_test_tags(test_suite,421 ['-fast,-slow,-safe',422 'does,not,exist'])423 self.assertEqual(len(filtered), 0)424 def test_python_unittest(self):425 disabled_test = script.TemporaryScript("disabled.py",426 AVOCADO_TEST_OK_DISABLED,427 mode=DEFAULT_NON_EXEC_MODE)428 python_unittest = script.TemporaryScript("python_unittest.py",429 PYTHON_UNITTEST)430 disabled_test.save()431 python_unittest.save()432 tests = self.loader.discover(disabled_test.path)433 self.assertEqual(tests, [])434 tests = self.loader.discover(python_unittest.path)...
test_tags.py
Source:test_tags.py
...96 self.assertEqual(self.test_suite[5][1]['methodName'], 'test_safe_x86')97 self.assertEqual(self.test_suite[6][0], 'NoTagsTest')98 self.assertEqual(self.test_suite[6][1]['methodName'], 'test_no_tags')99 def test_filter_fast_net(self):100 filtered = tags.filter_test_tags(self.test_suite, ['fast,net'], False, False)101 self.assertEqual(len(filtered), 2)102 self.assertEqual(filtered[0][0], 'FastTest')103 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')104 self.assertEqual(filtered[1][0], 'FastTest')105 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')106 def test_filter_fast_net_include_empty(self):107 filtered = tags.filter_test_tags(self.test_suite, ['fast,net'], True, False)108 self.assertEqual(len(filtered), 3)109 self.assertEqual(filtered[0][0], 'FastTest')110 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')111 self.assertEqual(filtered[1][0], 'FastTest')112 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')113 self.assertEqual(filtered[2][0], 'NoTagsTest')114 self.assertEqual(filtered[2][1]['methodName'], 'test_no_tags')115 def test_filter_arch(self):116 filtered = tags.filter_test_tags(self.test_suite, ['arch'], False, False)117 self.assertEqual(len(filtered), 1)118 self.assertEqual(filtered[0][0], 'SafeX86Test')119 self.assertEqual(filtered[0][1]['methodName'], 'test_safe_x86')120 def test_filter_arch_include_empty(self):121 filtered = tags.filter_test_tags(self.test_suite, ['arch'], True, False)122 self.assertEqual(len(filtered), 2)123 self.assertEqual(filtered[0][0], 'SafeX86Test')124 self.assertEqual(filtered[0][1]['methodName'], 'test_safe_x86')125 self.assertEqual(filtered[1][0], 'NoTagsTest')126 self.assertEqual(filtered[1][1]['methodName'], 'test_no_tags')127 def test_filter_arch_x86_64(self):128 filtered = tags.filter_test_tags(self.test_suite, ['arch:x86_64'], False, False)129 self.assertEqual(len(filtered), 1)130 self.assertEqual(filtered[0][0], 'SafeX86Test')131 self.assertEqual(filtered[0][1]['methodName'], 'test_safe_x86')132 def test_filter_arch_other(self):133 filtered = tags.filter_test_tags(self.test_suite, ['arch:ppc64'], False, False)134 self.assertEqual(len(filtered), 0)135 def test_filter_arch_other_include_empty_key(self):136 filtered = tags.filter_test_tags(self.test_suite, ['arch:ppc64'], False, True)137 self.assertEqual(len(filtered), 5)138 self.assertEqual(filtered[0][0], 'FastTest')139 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')140 self.assertEqual(filtered[1][0], 'FastTest')141 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')142 self.assertEqual(filtered[2][0], 'SlowTest')143 self.assertEqual(filtered[2][1]['methodName'], 'test_slow')144 self.assertEqual(filtered[3][0], 'SlowUnsafeTest')145 self.assertEqual(filtered[3][1]['methodName'], 'test_slow_unsafe')146 self.assertEqual(filtered[4][0], 'SafeTest')147 self.assertEqual(filtered[4][1]['methodName'], 'test_safe')148 def test_filter_arch_other_include_empty_flat_and_key(self):149 filtered = tags.filter_test_tags(self.test_suite, ['arch:ppc64'], True, True)150 self.assertEqual(len(filtered), 6)151 self.assertEqual(filtered[0][0], 'FastTest')152 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')153 self.assertEqual(filtered[1][0], 'FastTest')154 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')155 self.assertEqual(filtered[2][0], 'SlowTest')156 self.assertEqual(filtered[2][1]['methodName'], 'test_slow')157 self.assertEqual(filtered[3][0], 'SlowUnsafeTest')158 self.assertEqual(filtered[3][1]['methodName'], 'test_slow_unsafe')159 self.assertEqual(filtered[4][0], 'SafeTest')160 self.assertEqual(filtered[4][1]['methodName'], 'test_safe')161 self.assertEqual(filtered[5][0], 'NoTagsTest')162 self.assertEqual(filtered[5][1]['methodName'], 'test_no_tags')163 def test_filter_fast_net__slow_disk_unsafe(self):164 filtered = tags.filter_test_tags(self.test_suite,165 ['fast,net',166 'slow,disk,unsafe'],167 False, False)168 self.assertEqual(len(filtered), 3)169 self.assertEqual(filtered[0][0], 'FastTest')170 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')171 self.assertEqual(filtered[1][0], 'FastTest')172 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')173 self.assertEqual(filtered[2][0], 'SlowUnsafeTest')174 self.assertEqual(filtered[2][1]['methodName'], 'test_slow_unsafe')175 def test_filter_fast_net__slow_disk(self):176 filtered = tags.filter_test_tags(self.test_suite,177 ['fast,net',178 'slow,disk'],179 False, False)180 self.assertEqual(len(filtered), 4)181 self.assertEqual(filtered[0][0], 'FastTest')182 self.assertEqual(filtered[0][1]['methodName'], 'test_fast')183 self.assertEqual(filtered[1][0], 'FastTest')184 self.assertEqual(filtered[1][1]['methodName'], 'test_fast_other')185 self.assertEqual(filtered[2][0], 'SlowTest')186 self.assertEqual(filtered[2][1]['methodName'], 'test_slow')187 self.assertEqual(filtered[3][0], 'SlowUnsafeTest')188 self.assertEqual(filtered[3][1]['methodName'], 'test_slow_unsafe')189 def test_filter_not_fast_not_slow(self):190 filtered = tags.filter_test_tags(self.test_suite,191 ['-fast,-slow'],192 False)193 self.assertEqual(len(filtered), 2)194 self.assertEqual(filtered[0][0], 'SafeTest')195 self.assertEqual(filtered[0][1]['methodName'], 'test_safe')196 self.assertEqual(filtered[1][0], 'SafeX86Test')197 self.assertEqual(filtered[1][1]['methodName'], 'test_safe_x86')198 def test_filter_not_fast_not_slow_include_empty(self):199 filtered = tags.filter_test_tags(self.test_suite,200 ['-fast,-slow'],201 True)202 self.assertEqual(len(filtered), 3)203 self.assertEqual(filtered[0][0], 'SafeTest')204 self.assertEqual(filtered[0][1]['methodName'], 'test_safe')205 self.assertEqual(filtered[1][0], 'SafeX86Test')206 self.assertEqual(filtered[1][1]['methodName'], 'test_safe_x86')207 self.assertEqual(filtered[2][0], 'NoTagsTest')208 self.assertEqual(filtered[2][1]['methodName'], 'test_no_tags')209 def test_filter_not_fast_not_slow_not_safe(self):210 filtered = tags.filter_test_tags(self.test_suite,211 ['-fast,-slow,-safe'],212 False)213 self.assertEqual(len(filtered), 0)214 def test_filter_not_fast_not_slow_not_safe_others_dont_exist(self):215 filtered = tags.filter_test_tags(self.test_suite,216 ['-fast,-slow,-safe',217 'does,not,exist'],218 False)219 self.assertEqual(len(filtered), 0)220 def test_load_tags(self):221 tags_map = {222 'FastTest.test_fast': {'fast': None, 'net': None},223 'FastTest.test_fast_other': {'fast': None, 'net': None},224 'SlowTest.test_slow': {'slow': None, 'disk': None},225 'SlowUnsafeTest.test_slow_unsafe': {'slow': None,226 'disk': None,227 'unsafe': None},228 'SafeTest.test_safe': {'safe': None},229 'SafeX86Test.test_safe_x86': {'safe': None,230 'arch': set(['x86_64'])},231 'NoTagsTest.test_no_tags': {}232 }233 for _, info in self.test_suite:234 name = info['name'].split(':', 1)[1]235 self.assertEqual(info['tags'], tags_map[name])236 del(tags_map[name])237 self.assertEqual(len(tags_map), 0)238class TagFilter2(unittest.TestCase):239 def test_filter_tags_include_empty(self):240 with script.TemporaryScript('passtest.py',241 AVOCADO_TEST_OK,242 'avocado_loader_unittest',243 DEFAULT_NON_EXEC_MODE) as test_script:244 this_loader = loader.FileLoader(None, {})245 test_suite = this_loader.discover(test_script.path,246 loader.DiscoverMode.ALL)247 self.assertEqual([], tags.filter_test_tags(test_suite, [], False, False))248 self.assertEqual(test_suite,249 tags.filter_test_tags(test_suite, [], True, False))250class ParseFilterByTags(unittest.TestCase):251 def test_must(self):252 self.assertEqual(tags._parse_filter_by_tags(['foo,bar,baz']),253 [(set(['foo', 'bar', 'baz']), set([]))])254 def test_must_must_not(self):255 self.assertEqual(tags._parse_filter_by_tags(['foo,-bar,baz']),256 [(set(['foo', 'baz']), set(['bar']))])257 def test_musts_must_nots(self):258 self.assertEqual(tags._parse_filter_by_tags(['foo,bar,baz',259 '-FOO,-BAR,-BAZ']),260 [(set(['foo', 'bar', 'baz']), set([])),261 (set([]), set(['FOO', 'BAR', 'BAZ']))])262class FilterRunnable(unittest.TestCase):263 def test_no_tags(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!!