How to use load_suites_from_files method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_testsuite_loader.py

Source:test_testsuite_loader.py Github

copy

Full Screen

...48 assert suites[0].name == "parentsuite"49 assert suites[0].description == "Parentsuite"50 assert len(suites[0].get_suites()) == 151 assert suites[0].get_suites()[0].name == "childsuite"52def test_load_suites_from_files(tmpdir):53 for name in "suite1", "suite2", "mysuite":54 tmpdir.join(name + ".py").write(build_test_module(name))55 suites = load_suites_from_files(tmpdir.join("suite*.py").strpath)56 assert len(suites) == 257 assert suites[0].name == "suite1"58 assert suites[1].name == "suite2"59def test_load_suites_from_files_nomatch(tmpdir):60 suites = load_suites_from_files(tmpdir.join("*.py").strpath)61 assert len(suites) == 062def test_load_suites_from_files_exclude(tmpdir):63 for name in "suite1", "suite2", "mysuite":64 tmpdir.join(name + ".py").write(build_test_module(name))65 suites = load_suites_from_files(tmpdir.join("*.py").strpath, "*/suite*.py")66 assert len(suites) == 167 assert suites[0].name == "mysuite"68def test_load_suites_with_same_name():69 @lcc.suite("My Suite 1")70 class MySuite1:71 @lcc.suite("My Sub Suite 1")72 class MySubSuite:73 @lcc.test("foo")74 def foo(self):75 pass76 @lcc.suite("My Suite 2")77 class MySuite2:78 @lcc.suite("My Sub Suite 1")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):346 pass347 suite = load_suite_from_class(Suite)348 assert suite.has_hook("setup_suite")349 assert suite.has_hook("teardown_suite")350 assert suite.has_hook("setup_test")351 assert suite.has_hook("teardown_test")352def test_load_suite_from_class_with_fixture_dependencies():353 @lcc.suite("mysuite")354 class Suite:355 foo = lcc.inject_fixture()356 suite = load_suite_from_class(Suite)357 fixture_names = suite.get_fixtures()358 assert fixture_names == ["foo"]359def test_load_suite_from_file_with_single_suite(tmpdir):360 file = tmpdir.join("my_suite.py")361 file.write(362 """import lemoncheesecake.api as lcc363@lcc.suite()364class my_suite:365 @lcc.test()366 def my_test(self):367 pass368""")369 suite = load_suite_from_file(file.strpath)370 assert suite.name == "my_suite"371 assert len(suite.get_tests()) == 1372def test_load_suite_from_file_without_suite_marker(tmpdir):373 file = tmpdir.join("my_suite.py")374 file.write(375 """import lemoncheesecake.api as lcc376@lcc.test()377def my_test(self):378 pass379""")380 suite = load_suite_from_file(file.strpath)381 assert suite.name == "my_suite"382 assert len(suite.get_tests()) == 1383def test_load_suite_from_file_empty_module(tmpdir):384 file = tmpdir.join("my_suite.py")385 file.write("")386 suite = load_suite_from_file(file.strpath)387 assert suite.name == "my_suite"388 assert suite.description == "My suite"389 assert len(suite.get_tests()) == 0390def test_load_suite_from_file_tests_order(tmpdir):391 file = tmpdir.join("mysuite.py")392 file.write(393 """394import lemoncheesecake.api as lcc395SUITE = {396 "description": "My Suite"397}398@lcc.test("a")399def a():400 pass401@lcc.test("d")402def d():403 pass404@lcc.test("c")405def c():406 pass407@lcc.test("b")408def b():409 pass410""")411 suite = load_suite_from_file(file.strpath)412 tests = suite.get_tests()413 assert tests[0].name == "a"414 assert tests[1].name == "d"415 assert tests[2].name == "c"416 assert tests[3].name == "b"417def test_load_suite_from_file_suites_order(tmpdir):418 file = tmpdir.join("mysuite.py")419 file.write(420 """421import lemoncheesecake.api as lcc422SUITE = {423 "description": "My Suite"424}425@lcc.suite("a")426class a:427 @lcc.test("test")428 def test(self):429 pass430@lcc.suite("d")431class d:432 @lcc.test("test")433 def test(self):434 pass435@lcc.suite("c")436class c:437 @lcc.test("test")438 def test(self):439 pass440@lcc.suite("b")441class b:442 @lcc.test("test")443 def test(self):444 pass445""")446 suite = load_suite_from_file(file.strpath)447 suites = suite.get_suites()448 assert suites[0].name == "a"449 assert suites[1].name == "d"450 assert suites[2].name == "c"451 assert suites[3].name == "b"452def test_load_suite_from_file_with_fixture_dependencies(tmpdir):453 file = tmpdir.join("mysuite.py")454 file.write(455 """import lemoncheesecake.api as lcc456SUITE = {457 "description": "My Suite"458}459foo = lcc.inject_fixture()460""")461 suite = load_suite_from_file(file.strpath)462 fixture_names = suite.get_fixtures()463 assert fixture_names == ["foo"]464def test_load_suite_from_file_with_all_metadata(tmpdir):465 file = tmpdir.join("mysuite.py")466 file.write(467 """SUITE = {468 "name": "my_suite",469 "description": "My Suite",470 "tags": ["foo", "bar"],471 "properties": {"bar": "baz"},472 "links": [("http://u.r.l/1234", None), ("http://u.r.l/1235", "#1235"), "http://u.r.l/1236"],473}474""")475 suite = load_suite_from_file(file.strpath)476 assert suite.name == "my_suite"477 assert suite.description == "My Suite"478 assert suite.tags == ["foo", "bar"]479 assert suite.properties == {"bar": "baz"}480 assert suite.links == [("http://u.r.l/1234", None), ("http://u.r.l/1235", "#1235"), ("http://u.r.l/1236", None)]481def test_load_suite_from_file_with_test_function(tmpdir):482 file = tmpdir.join("mysuite.py")483 file.write(484 """import lemoncheesecake.api as lcc485SUITE = {486 "description": "My Suite"487}488@lcc.test('My Test')489def mytest():490 pass491""")492 suite = load_suite_from_file(file.strpath)493 test = suite.get_tests()[0]494 assert test.name == "mytest"495 assert test.description == "My Test"496def test_load_suite_from_files_with_condition_on_suite_met(tmpdir):497 file = tmpdir.join("mysuite.py")498 file.write(499 """import lemoncheesecake.api as lcc500import sys501SUITE = {502 "description": "My Suite",503 "visible_if": lambda mod: mod == sys.modules[__name__]504}505@lcc.test('My Test')506def mytest():507 pass508""")509 suites = load_suites_from_files([file.strpath])510 assert len(suites) == 1511def test_load_suite_from_files_with_condition_on_suite_not_met(tmpdir):512 file = tmpdir.join("mysuite.py")513 file.write(514 """import lemoncheesecake.api as lcc515import sys516SUITE = {517 "description": "My Suite",518 "visible_if": lambda mod: mod != sys.modules[__name__]519}520@lcc.test('My Test')521def mytest():522 pass523""")524 suites = load_suites_from_files([file.strpath])525 assert len(suites) == 0526def test_load_suite_from_files_with_condition_on_test_met(tmpdir):527 file = tmpdir.join("mysuite.py")528 file.write(529 """import lemoncheesecake.api as lcc530SUITE = {531 "description": "My Suite",532}533@lcc.test('My Test')534@lcc.visible_if(lambda test_arg: test_arg == mytest)535def mytest():536 pass537""")538 suites = load_suites_from_files([file.strpath])539 assert len(suites[0].get_tests()) == 1540def test_load_suite_from_module_with_condition_on_test_not_met(tmpdir):541 file = tmpdir.join("mysuite.py")542 file.write(543 """import lemoncheesecake.api as lcc544SUITE = {545 "description": "My Suite",546}547@lcc.test('My Test')548@lcc.visible_if(lambda test_arg: test_arg != mytest)549def mytest():550 pass551""")552 suites = load_suites_from_files([file.strpath])553 assert len(suites) == 0554def test_load_suite_from_file_with_test_function_and_fixtures(tmpdir):555 file = tmpdir.join("mysuite.py")556 file.write(557 """import lemoncheesecake.api as lcc558SUITE = {559 "description": "My Suite"560}561@lcc.test('My Test')562def mytest(fixt1, fixt2):563 pass564""")565 suite = load_suite_from_file(file.strpath)566 test = suite.get_tests()[0]...

Full Screen

Full Screen

loader.py

Source:loader.py Github

copy

Full Screen

...193 len(suite.get_tests()) == 0 and len(suite.get_suites()) == 1 and suite.get_suites()[0].name == mod_name:194 suite = suite.get_suites()[0]195 suite.parent_suite = None196 return suite197def load_suites_from_files(patterns, excluding=()):198 # type: (Sequence[str], Sequence[str]) -> List[Suite]199 """200 Load a list of suites from a list of files.201 :param patterns: a mandatory list (a simple string can also be used instead of a single element list)202 of files to import; the wildcard '*' character can be used203 :param excluding: an optional list (a simple string can also be used instead of a single element list)204 of elements to exclude from the expanded list of files to import205 Example::206 load_suites_from_files("test_*.py")207 """208 return list(209 filter(210 lambda suite: not suite.hidden and not suite.is_empty(),211 map(load_suite_from_file, get_matching_files(patterns, excluding))212 )213 )214def load_suites_from_directory(dir, recursive=True):215 # type: (str, bool) -> List[Suite]216 """217 Load a list of suites from a directory.218 If the recursive argument is set to True, sub suites will be searched in a directory named219 from the suite module: if the suite module is "foo.py" then the sub suites directory must be "foo".220 Raise SuiteLoadingError if one or more suite could not be loaded....

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 Lemoncheesecake 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