Best Python code snippet using lemoncheesecake
test_testsuite_loader.py
Source:test_testsuite_loader.py
...79 class MySubSuite:80 @lcc.test("bar")81 def bar(self):82 pass83 suites = load_suites_from_classes([MySuite1, MySuite2])84 assert suites[0].name == "MySuite1"85 assert suites[0].get_suites()[0].name == "MySubSuite"86 assert suites[1].name == "MySuite2"87 assert suites[1].get_suites()[0].name == "MySubSuite"88def test_load_tests_with_same_name():89 @lcc.suite("My Suite 1")90 class MySuite1:91 @lcc.suite("My Sub Suite 1")92 class MySubSuite1:93 @lcc.test("foo")94 def foo(self):95 pass96 @lcc.suite("My Suite 2")97 class MySuite2:98 @lcc.suite("My Sub Suite 2")99 class MySubSuite2:100 @lcc.test("foo")101 def foo(self):102 pass103 suites = load_suites_from_classes([MySuite1, MySuite2])104 assert suites[0].name == "MySuite1"105 assert suites[0].get_suites()[0].name == "MySubSuite1"106 assert suites[0].get_suites()[0].get_tests()[0].name == "foo"107 assert suites[1].name == "MySuite2"108 assert suites[1].get_suites()[0].name == "MySubSuite2"109 assert suites[1].get_suites()[0].get_tests()[0].name == "foo"110def test_load_suite_from_class_tests_order():111 @lcc.suite("suite")112 class suite:113 @lcc.test("a")114 def a(self):115 pass116 @lcc.test("d")117 def d(self):118 pass119 @lcc.test("c")120 def c(self):121 pass122 @lcc.test("b")123 def b(self):124 pass125 suite = load_suite_from_class(suite)126 tests = suite.get_tests()127 assert tests[0].name == "a"128 assert tests[1].name == "d"129 assert tests[2].name == "c"130 assert tests[3].name == "b"131def test_load_suite_from_class_suites_order():132 @lcc.suite("suite")133 class suite:134 @lcc.suite("a")135 class a:136 @lcc.test("test")137 def test(self):138 pass139 @lcc.suite("d")140 class d:141 @lcc.test("test")142 def test(self):143 pass144 @lcc.suite("c")145 class c:146 @lcc.test("test")147 def test(self):148 pass149 @lcc.suite("b")150 class b:151 @lcc.test("test")152 def test(self):153 pass154 suite = load_suite_from_class(suite)155 suites = suite.get_suites()156 assert suites[0].name == "a"157 assert suites[1].name == "d"158 assert suites[2].name == "c"159 assert suites[3].name == "b"160def test_metadata_policy():161 @lcc.suite("My Suite 1")162 class MySuite1:163 @lcc.prop("foo", "3")164 @lcc.test("Some test")165 def sometest(self):166 pass167 @lcc.suite("My Suite 1")168 @lcc.prop("foo", "3")169 class MySuite2:170 @lcc.test("Some test")171 def sometest(self):172 pass173 suite1 = load_suites_from_classes([MySuite1])174 suite2 = load_suites_from_classes([MySuite2])175 policy = MetadataPolicy()176 policy.add_property_rule("foo", ("1", "2"))177 with pytest.raises(MetadataPolicyViolation):178 policy.check_suites_compliance(suite1)179 with pytest.raises(MetadataPolicyViolation):180 policy.check_suites_compliance(suite2)181def test_load_suites_from_classes_with_condition_on_suite_met():182 @lcc.suite("My Suite")183 @lcc.visible_if(lambda suite_arg: suite_arg.__class__ == MySuite)184 class MySuite:185 @lcc.test("My Test")186 def mytest(self):187 pass188 suites = load_suites_from_classes([MySuite])189 assert len(suites) == 1190def test_load_suites_from_classes_with_condition_on_suite_not_met():191 @lcc.suite("My Suite")192 @lcc.visible_if(lambda suite_arg: suite_arg.__class__ != MySuite)193 class MySuite:194 @lcc.test("My Test")195 def mytest(self):196 pass197 suites = load_suites_from_classes([MySuite])198 assert len(suites) == 0199def test_load_suites_from_classes_with_condition_on_test_met():200 @lcc.suite("My Suite")201 class MySuite:202 @lcc.test("My Test")203 @lcc.visible_if(lambda test_arg: six.get_method_function(test_arg) == six.get_unbound_function((MySuite.mytest)))204 def mytest(self):205 pass206 suites = load_suites_from_classes([MySuite])207 assert len(suites[0].get_tests()) == 1208def test_load_suites_from_classes_with_condition_on_test_not_met():209 @lcc.suite("My Suite")210 class MySuite:211 @lcc.test("My Test")212 @lcc.visible_if(lambda test_arg: six.get_method_function(test_arg) != six.get_unbound_function(MySuite.mytest))213 def mytest(self):214 pass215 suites = load_suites_from_classes([MySuite])216 assert len(suites[0].get_tests()) == 0217def test_load_parametrized_test():218 @lcc.suite("suite")219 class MySuite:220 @lcc.test("test")221 @lcc.parametrized(({"value": 1}, {"value": 2}))222 @lcc.tags("mytag")223 def test(self, value):224 pass225 suite = load_suite_from_class(MySuite)226 tests = suite.get_tests()227 assert len(tests) == 2228 assert tests[0].name == "test_1"229 assert tests[0].description == "test #1"230 assert tests[0].tags == ["mytag"]231 assert tests[1].name == "test_2"232 assert tests[1].description == "test #2"233 assert tests[1].tags == ["mytag"]234def test_load_parametrized_test_no_parameters():235 @lcc.suite()236 class MySuite:237 @lcc.test()238 @lcc.parametrized(())239 def test(self, value):240 pass241 suite = load_suite_from_class(MySuite)242 tests = suite.get_tests()243 assert len(tests) == 0244def test_load_parametrized_test_csv_like():245 @lcc.suite("suite")246 class MySuite:247 @lcc.test("test")248 @lcc.parametrized(("i,j", (1, 2), (3, 4)))249 def test(self, i, j):250 pass251 suite = load_suite_from_class(MySuite)252 tests = suite.get_tests()253 assert len(tests) == 2254 assert tests[0].name == "test_1"255 assert tests[0].description == "test #1"256 assert tests[1].name == "test_2"257 assert tests[1].description == "test #2"258def test_load_parametrized_test_csv_like_with_header_as_tuple():259 @lcc.suite("suite")260 class MySuite:261 @lcc.test("test")262 @lcc.parametrized((("i", "j"), (1, 2), (3, 4)))263 def test(self, i, j):264 pass265 suite = load_suite_from_class(MySuite)266 tests = suite.get_tests()267 assert len(tests) == 2268 assert tests[0].name == "test_1"269 assert tests[0].description == "test #1"270 assert tests[1].name == "test_2"271 assert tests[1].description == "test #2"272def test_load_parametrized_test_from_iterator():273 def my_iterator():274 yield {"value": 1}275 yield {"value": 2}276 @lcc.suite("suite")277 class MySuite:278 @lcc.test("test")279 @lcc.parametrized(my_iterator())280 def test(self, value):281 pass282 suite = load_suite_from_class(MySuite)283 tests = suite.get_tests()284 assert len(tests) == 2285 assert tests[0].name == "test_1"286 assert tests[0].description == "test #1"287 assert tests[1].name == "test_2"288 assert tests[1].description == "test #2"289def test_load_parametrized_test_custom_naming():290 def naming_scheme(name, description, parameters, idx):291 return "%s_%s" % (name, parameters["value"]), "%s %s" % (description, parameters["value"])292 @lcc.suite("suite")293 class MySuite:294 @lcc.test("test")295 @lcc.parametrized(({"value": "foo"},), naming_scheme)296 def test(self, value):297 pass298 suite = load_suite_from_class(MySuite)299 test = suite.get_tests()[0]300 assert test.name == "test_foo"301 assert test.description == "test foo"302def test_load_parametrized_test_custom_naming_with_format():303 @lcc.suite("suite")304 class MySuite:305 @lcc.test()306 @lcc.parametrized(({"value": "foo"},), ("test_{value}", "test {value}"))307 def test(self, value):308 pass309 suite = load_suite_from_class(MySuite)310 test = suite.get_tests()[0]311 assert test.name == "test_foo"312 assert test.description == "test foo"313def test_load_parametrized_test_csv_like_custom_naming_with_format():314 @lcc.suite("suite")315 class MySuite:316 @lcc.test("test")317 @lcc.parametrized(("value", ("foo",)), ("test_{value}", "test {value}"))318 def test(self, value):319 pass320 suite = load_suite_from_class(MySuite)321 test = suite.get_tests()[0]322 assert test.name == "test_foo"323 assert test.description == "test foo"324def test_hidden_test():325 @lcc.suite("My Suite")326 class MySuite:327 @lcc.test("My Test")328 @lcc.hidden()329 def mytest(self):330 pass331 suites = load_suites_from_classes([MySuite])332 assert len(suites[0].get_tests()) == 0333def test_load_suite_from_class_with_hooks():334 @lcc.suite("mysuite")335 class Suite:336 def setup_suite(self):337 return 1338 def teardown_suite(self):339 return 2340 def setup_test(self, test):341 return 3342 def teardown_test(self, test, status):343 return 4344 @lcc.test("some test")345 def sometest(self):...
test_testtree.py
Source:test_testtree.py
...113 class mysuite2:114 @lcc.test("Test 2")115 def test2(self):116 pass117 suites = load_suites_from_classes([mysuite1, mysuite2])118 flattened_suites = flatten_suites(suites)119 assert [s.name for s in flattened_suites] == ["mysuite1", "mysuite2"]120def test_flatten_suites_on_nested_suites():121 @lcc.suite("My suite 1")122 class mysuite1:123 @lcc.suite("My suite 2")124 class mysuite2:125 @lcc.test("Test")126 def test(self):127 pass128 @lcc.suite("My suite 3")129 class mysuite3:130 @lcc.suite("My suite 4")131 class mysuite4:132 @lcc.test("Test")133 def test(self):134 pass135 suites = load_suites_from_classes([mysuite1, mysuite3])136 flattened_suites = flatten_suites(suites)137 assert [s.name for s in flattened_suites] == ["mysuite1", "mysuite2", "mysuite3", "mysuite4"]138def test_flatten_tests():139 @lcc.suite("My suite 1")140 class mysuite1:141 @lcc.test("Test 1")142 def test1(self):143 pass144 @lcc.suite("My suite 2")145 class mysuite2:146 @lcc.test("Test 2")147 def test2(self):148 pass149 suites = load_suites_from_classes([mysuite1, mysuite2])150 tests = flatten_tests(suites)151 assert [t.name for t in tests] == ["test1", "test2"]152def test_flatten_tests_on_nested_suites():153 @lcc.suite("My suite 1")154 class mysuite1:155 @lcc.test("Test 1")156 def test1(self):157 pass158 @lcc.suite("My suite 2")159 class mysuite2:160 @lcc.test("Test 2")161 def test2(self):162 pass163 @lcc.suite("My suite 3")164 class mysuite3:165 @lcc.test("Test 3")166 def test3(self):167 pass168 @lcc.suite("My suite 4")169 class mysuite4:170 @lcc.test("Test 4")171 def test4(self):172 pass173 suites = load_suites_from_classes([mysuite1, mysuite3])174 tests = flatten_tests(suites)175 assert [t.name for t in tests] == ["test1", "test2", "test3", "test4"]176def test_find_suite_top():177 @lcc.suite("My suite 1")178 class mysuite1:179 pass180 @lcc.suite("My suite 2")181 class mysuite2:182 pass183 suites = load_suites_from_classes([mysuite1, mysuite2])184 suite = find_suite(suites, "mysuite2")185 assert suite.name == "mysuite2"186def test_find_suite_nested():187 @lcc.suite("My suite 1")188 class mysuite1:189 @lcc.suite("My suite 2")190 class mysuite2:191 pass192 suites = load_suites_from_classes([mysuite1])193 suite = find_suite(suites, "mysuite1.mysuite2")194 assert suite.name == "mysuite2"195def test_find_suite_unknown():196 @lcc.suite("My suite 1")197 class mysuite1:198 pass199 suites = load_suites_from_classes([mysuite1])200 with pytest.raises(LookupError):201 find_suite(suites, "unknownsuite")202def test_find_test():203 @lcc.suite("My suite 1")204 class mysuite1:205 @lcc.test("My test")206 def mytest(self):207 pass208 suites = load_suites_from_classes([mysuite1])209 test = find_test(suites, "mysuite1.mytest")210 assert test.name == "mytest"211def test_find_test_unknown():212 @lcc.suite("My suite 1")213 class mysuite1:214 @lcc.test("My test")215 def mytest(self):216 pass217 suites = load_suites_from_classes([mysuite1])218 with pytest.raises(LookupError):219 find_test(suites, "mysuite1.unknown")220def test_is_empty_on_suite_with_test():221 @lcc.suite("My suite 1")222 class mysuite1:223 @lcc.test("My test")224 def mytest(self):225 pass226 suite = load_suite_from_class(mysuite1)227 assert not suite.is_empty()228def test_is_empty_on_sub_suite_with_test():229 @lcc.suite("My suite 1")230 class mysuite1:231 @lcc.suite("My suite 2")...
runner.py
Source:runner.py
...103 dump_report(session.report)104 return session.report105def run_suite_classes(suite_classes, fixtures=None, backends=None, tmpdir=None,106 force_disabled=False, stop_on_failure=False, report_saving_strategy=None, nb_threads=1):107 suites = load_suites_from_classes(suite_classes)108 return run_suites(109 suites, fixtures=fixtures, backends=backends, tmpdir=tmpdir,110 force_disabled=force_disabled, stop_on_failure=stop_on_failure,111 report_saving_strategy=report_saving_strategy, nb_threads=nb_threads112 )113def run_suite(suite, fixtures=None, backends=[], tmpdir=None, force_disabled=False, stop_on_failure=False,114 report_saving_strategy=None, nb_threads=1):115 return run_suites(116 [suite], fixtures=fixtures, backends=backends, tmpdir=tmpdir,117 force_disabled=force_disabled, stop_on_failure=stop_on_failure,118 report_saving_strategy=report_saving_strategy, nb_threads=nb_threads119 )120def run_suite_class(suite_class, fixtures=None, backends=[], tmpdir=None,121 force_disabled=False, stop_on_failure=False, report_saving_strategy=None, nb_threads=1):...
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!!