Best Python code snippet using lemoncheesecake
test_project.py
Source:test_project.py
...104 def test(self):105 lcc.log_info("some log")106 class MyProject(Project):107 def load_suites(self):108 return [load_suite_from_class(suite)]109 project = MyProject(tmpdir.strpath)110 report = run_project(111 project, project.load_suites(), None, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")112 )113 assert report.is_successful()114def test_run_project_with_pre_run(tmpdir):115 pre_run_args = []116 @lcc.suite("suite")117 class suite:118 @lcc.test("test")119 def test(self):120 lcc.log_info("some log")121 class MyProject(Project):122 def pre_run(self, cli_args, report_dir):123 pre_run_args.extend((cli_args, report_dir))124 def load_suites(self):125 return [load_suite_from_class(suite)]126 project = MyProject(tmpdir.strpath)127 report = run_project(128 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")129 )130 assert report.is_successful()131 assert pre_run_args == [NotImplemented, tmpdir.strpath]132def test_run_project_with_pre_run_exception(tmpdir):133 @lcc.suite("suite")134 class suite:135 @lcc.test("test")136 def test(self):137 lcc.log_info("some log")138 class MyProject(Project):139 def pre_run(self, cli_args, report_dir):140 raise Exception("error from pre_run")141 def load_suites(self):142 return [load_suite_from_class(suite)]143 project = MyProject(tmpdir.strpath)144 with pytest.raises(LemoncheesecakeException, match=re.compile("error from pre_run")):145 run_project(146 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")147 )148def test_run_project_with_post_run(tmpdir):149 post_run_args = []150 @lcc.suite("suite")151 class suite:152 @lcc.test("test")153 def test(self):154 lcc.log_info("some log")155 class MyProject(Project):156 def post_run(self, cli_args, report_dir):157 post_run_args.extend((cli_args, report_dir))158 def load_suites(self):159 return [load_suite_from_class(suite)]160 project = MyProject(tmpdir.strpath)161 report = run_project(162 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")163 )164 assert report.is_successful()165 assert post_run_args == [NotImplemented, tmpdir.strpath]166def test_run_project_with_post_run_exception(tmpdir):167 @lcc.suite("suite")168 class suite:169 @lcc.test("test")170 def test(self):171 lcc.log_info("some log")172 class MyProject(Project):173 def post_run(self, cli_args, report_dir):174 raise Exception("error from post_run")175 def load_suites(self):176 return [load_suite_from_class(suite)]177 project = MyProject(tmpdir.strpath)178 with pytest.raises(LemoncheesecakeException, match=re.compile("error from post_run")):179 run_project(180 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")181 )182 session = Session.get()183 assert session.report.is_successful()184def test_run_project_with_build_report_title(tmpdir):185 @lcc.suite("suite")186 class suite:187 @lcc.test("test")188 def test(self):189 lcc.log_info("some log")190 class MyProject(Project):191 def build_report_title(self):192 return "Custom Report Title"193 def load_suites(self):194 return [load_suite_from_class(suite)]195 project = MyProject(tmpdir.strpath)196 report = run_project(197 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")198 )199 assert report.is_successful()200 assert report.title == "Custom Report Title"201def test_run_project_with_build_report_info(tmpdir):202 @lcc.suite("suite")203 class suite:204 @lcc.test("test")205 def test(self):206 lcc.log_info("some log")207 class MyProject(Project):208 def build_report_info(self):209 return [("key", "value")]210 def load_suites(self):211 return [load_suite_from_class(suite)]212 project = MyProject(tmpdir.strpath)213 report = run_project(214 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")215 )216 assert report.is_successful()217 assert report.info == [["key", "value"]]218def test_run_project_with_fixtures(tmpdir):219 test_args = []220 @lcc.fixture()221 def fixt():222 return 42223 @lcc.suite("suite")224 class suite:225 @lcc.test("test")226 def test(self, fixt):227 test_args.append(fixt)228 class MyProject(Project):229 def load_fixtures(self):230 return load_fixtures_from_func(fixt)231 def load_suites(self):232 return [load_suite_from_class(suite)]233 project = MyProject(tmpdir.strpath)234 report = run_project(235 project, project.load_suites(), NotImplemented, [], tmpdir.strpath,236 make_report_saving_strategy("at_end_of_tests")237 )238 assert report.is_successful()239 assert test_args == [42]240def test_run_project_with_fixture_error(tmpdir):241 @lcc.suite("suite")242 class suite:243 @lcc.test("test")244 def test(self, missing_fixture):245 pass246 class MyProject(Project):247 def load_suites(self):248 return [load_suite_from_class(suite)]249 project = MyProject(tmpdir.strpath)250 with pytest.raises(FixtureConstraintViolation):251 run_project(252 project, project.load_suites(), NotImplemented, [], tmpdir.strpath,253 make_report_saving_strategy("at_end_of_tests")254 )255def test_run_project_with_fixture_cli_args(tmpdir):256 test_args = []257 @lcc.suite("suite")258 class suite:259 @lcc.test("test")260 def test(self, cli_args):261 test_args.append(cli_args)262 class MyProject(Project):263 def load_suites(self):264 return [load_suite_from_class(suite)]265 project = MyProject(tmpdir.strpath)266 report = run_project(267 project, project.load_suites(), NotImplemented, [], tmpdir.strpath,268 make_report_saving_strategy("at_end_of_tests")269 )270 assert report.is_successful()271 assert test_args == [NotImplemented]272def test_run_project_with_fixture_project_dir(tmpdir):273 test_args = []274 @lcc.suite("suite")275 class suite:276 @lcc.test("test")277 def test(self, project_dir):278 test_args.append(project_dir)279 class MyProject(Project):280 def load_suites(self):281 return [load_suite_from_class(suite)]282 project = MyProject(tmpdir.strpath)283 report = run_project(284 project, project.load_suites(), NotImplemented, [], tmpdir.strpath,285 make_report_saving_strategy("at_end_of_tests")286 )287 assert report.is_successful()288 assert test_args == [tmpdir.strpath]289def test_run_project_with_custom_nb_threads(tmpdir):290 @lcc.suite("suite")291 class suite:292 @lcc.test("test")293 def test(self):294 lcc.log_info("some log")295 class MyProject(Project):296 def load_suites(self):297 return [load_suite_from_class(suite)]298 project = MyProject(tmpdir.strpath)299 report = run_project(300 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests"),301 nb_threads=2302 )303 assert report.is_successful()304 assert report.nb_threads == 2305def test_run_project_with_force_disabled(tmpdir):306 @lcc.suite("suite")307 class suite:308 @lcc.test("test")309 @lcc.disabled()310 def test(self):311 lcc.log_info("some log")312 class MyProject(Project):313 def load_suites(self):314 return [load_suite_from_class(suite)]315 project = MyProject(tmpdir.strpath)316 report = run_project(317 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests"),318 force_disabled=True319 )320 test, = list(report.all_tests())321 assert test.status == "passed"322def test_run_project_with_stop_on_failure(tmpdir):323 @lcc.suite("suite")324 class suite:325 @lcc.test("test_1")326 def test_1(self):327 lcc.log_error("something wrong happened")328 @lcc.test("test_2")329 def test_2(self):330 lcc.log_info("everything's fine")331 class MyProject(Project):332 def load_suites(self):333 return [load_suite_from_class(suite)]334 project = MyProject(tmpdir.strpath)335 report = run_project(336 project, project.load_suites(), NotImplemented, [], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests"),337 stop_on_failure=True338 )339 test_1, test_2 = list(report.all_tests())340 assert test_1.status == "failed"341 assert test_2.status == "skipped"342def test_run_project_with_reporting_backends(tmpdir):343 @lcc.suite("suite")344 class suite:345 @lcc.test("test")346 def test(self):347 lcc.log_info("some log")348 class MyProject(Project):349 def load_suites(self):350 return [load_suite_from_class(suite)]351 project = MyProject(tmpdir.strpath)352 report = run_project(353 project, project.load_suites(), None, [JsonBackend()], tmpdir.strpath, make_report_saving_strategy("at_end_of_tests")354 )355 assert report.is_successful()...
test_testsuite.py
Source:test_testsuite.py
...13 class MySuite:14 @lcc.test("test_desc")15 def mytest(self):16 pass17 suite = load_suite_from_class(MySuite)18 test = suite.get_tests()[0]19 assert test.name == "mytest"20 assert test.description == "test_desc"21def test_decorator_test_without_description():22 @lcc.suite("My Suite")23 class MySuite:24 @lcc.test()25 def my_test(self):26 pass27 suite = load_suite_from_class(MySuite)28 test = suite.get_tests()[0]29 assert test.name == "my_test"30 assert test.description == "My test"31def test_decorator_test_with_name():32 @lcc.test("My Test", name="mytest")33 def sometest():34 pass35 metadata = lcc.get_metadata(sometest)36 assert metadata.name == "mytest"37def test_decorator_tags():38 @lcc.suite("My Suite")39 @lcc.tags("tag3")40 class MySuite:41 @lcc.test("test_desc")42 @lcc.tags("tag1", "tag2")43 def mytest(self):44 pass45 suite = load_suite_from_class(MySuite)46 assert suite.tags == ["tag3"]47 test = suite.get_tests()[0]48 assert test.tags == ["tag1", "tag2"]49def test_decorator_prop():50 @lcc.suite("My Suite")51 @lcc.prop("key1", "val1")52 class MySuite:53 @lcc.test("test_desc")54 @lcc.prop("key2", "val2")55 def mytest(self):56 pass57 suite = load_suite_from_class(MySuite)58 assert suite.properties["key1"] == "val1"59 test = suite.get_tests()[0]60 assert test.properties["key2"] == "val2"61def test_decorator_link():62 @lcc.suite("My Suite")63 @lcc.link("http://www.example.com", "example")64 class MySuite:65 @lcc.test("test_desc")66 @lcc.link("http://www.example.com")67 def mytest(self):68 pass69 suite = load_suite_from_class(MySuite)70 assert suite.links[0] == ("http://www.example.com", "example")71 test = suite.get_tests()[0]72 assert test.links[0] == ("http://www.example.com", None)73def test_test_decorator_on_invalid_object():74 with pytest.raises(AssertionError):75 @lcc.test("test")76 class NotAFunction:77 pass78def test_decorator_suite_with_name():79 @lcc.suite("My Suite", name="mysuite")80 class somesuite():81 pass82 suite = load_suite_from_class(somesuite)83 assert suite.name == "mysuite"84def test_decorator_suite_without_description():85 @lcc.suite()86 class some_suite():87 pass88 suite = load_suite_from_class(some_suite)89 assert suite.description == "Some suite"90def test_suite_decorator_on_invalid_object():91 with pytest.raises(AssertionError):92 @lcc.suite("suite")93 def not_a_class():94 pass95def test_decorator_with_suite_inheritance():96 @lcc.suite("My Suite 1")97 @lcc.link("http://www.example1.com")98 @lcc.tags("tag1", "tag2")99 @lcc.prop("key1", "value1")100 class MySuite1:101 pass102 @lcc.suite("My Suite 2")103 @lcc.link("http://www.example2.com")104 @lcc.tags("tag3")105 @lcc.prop("key2", "value2")106 class MySuite2(MySuite1):107 pass108 suite1 = load_suite_from_class(MySuite1)109 suite2 = load_suite_from_class(MySuite2)110 assert len(suite1.links) == 1111 assert suite1.links[0] == ("http://www.example1.com", None)112 assert suite1.tags == ["tag1", "tag2"]113 assert len(suite1.properties) == 1114 assert suite1.properties["key1"] == "value1"115 assert len(suite2.links) == 2116 assert suite2.links[0] == ("http://www.example1.com", None)117 assert suite2.links[1] == ("http://www.example2.com", None)118 assert suite2.tags == ["tag1", "tag2", "tag3"]119 assert len(suite2.properties) == 2120 assert suite2.properties["key1"] == "value1"121 assert suite2.properties["key2"] == "value2"122def test_decorator_unicode():123 @lcc.suite(u"My Suite éééà à à ")124 @lcc.link("http://foo.bar", u"éééà à à ")125 @lcc.prop(u"ééé", u"à à à ")126 @lcc.tags(u"ééé", u"à à à ")127 class MySuite:128 @lcc.test(u"Some test à à à ")129 @lcc.link("http://foo.bar", u"éééà à à ")130 @lcc.prop(u"ééé", u"à à à ")131 @lcc.tags(u"ééé", u"à à à ")132 def sometest(self):133 pass134 suite = load_suite_from_class(MySuite)135 assert suite.links[0] == ("http://foo.bar", u"éééà à à ")136 assert suite.properties[u"ééé"] == u"à à à "137 assert suite.tags == [u"ééé", u"à à à "]138 test = suite.get_tests()[0]139 assert test.description == u"Some test à à à "140 assert test.links[0] == ("http://foo.bar", u"éééà à à ")141 assert test.properties[u"ééé"] == u"à à à "142 assert test.tags == [u"ééé", u"à à à "]143def test_duplicated_suite_description():144 @lcc.suite("My Suite")145 class MySuite:146 @lcc.suite("somedesc")147 class SubSuite1:148 pass149 @lcc.suite("somedesc")150 class SubSuite2:151 pass152 with pytest.raises(SuiteLoadingError, match="is already registered"):153 load_suite_from_class(MySuite)154def test_duplicated_test_description():155 @lcc.suite("My Suite")156 class MySuite:157 @lcc.test("somedesc")158 def foo(self):159 pass160 @lcc.test("somedesc")161 def bar(self):162 pass163 with pytest.raises(SuiteLoadingError, match="is already registered"):164 load_suite_from_class(MySuite)165def test_duplicated_test_name():166 @lcc.suite("My Suite")167 class MySuite:168 def __init__(self):169 add_test_into_suite(lcc.Test("mytest", "First test", dummy_test_callback()), self)170 add_test_into_suite(lcc.Test("mytest", "Second test", dummy_test_callback()), self)171 with pytest.raises(SuiteLoadingError, match="is already registered"):172 load_suite_from_class(MySuite)173def test_suite_rank():174 @lcc.suite("My Suite")175 class MySuite1:176 @lcc.suite("D")177 class D:178 @lcc.test("test")179 def test(self): pass180 @lcc.suite("C")181 class C:182 @lcc.test("test")183 def test(self): pass184 @lcc.suite("B")185 class B:186 @lcc.test("test")187 def test(self): pass188 @lcc.suite("A")189 class A:190 @lcc.test("test")191 def test(self): pass192 suite = load_suite_from_class(MySuite1)193 assert suite.get_suites()[0].name == "D"194 assert suite.get_suites()[1].name == "C"195 assert suite.get_suites()[2].name == "B"196 assert suite.get_suites()[3].name == "A"197def test_suite_rank_forced():198 @lcc.suite("My Suite")199 class MySuite1:200 @lcc.suite("A", rank=2)201 class A:202 @lcc.test("test")203 def test(self): pass204 @lcc.suite("B", rank=3)205 class B:206 @lcc.test("test")207 def test(self): pass208 @lcc.suite("C", rank=1)209 class C:210 @lcc.test("test")211 def test(self): pass212 @lcc.suite("D", rank=4)213 class D:214 @lcc.test("test")215 def test(self): pass216 suite = load_suite_from_class(MySuite1)217 assert suite.get_suites()[0].name == "C"218 assert suite.get_suites()[1].name == "A"219 assert suite.get_suites()[2].name == "B"220 assert suite.get_suites()[3].name == "D"221def test_add_test_into_suite_with_function():222 def func():223 pass224 @lcc.suite("My Suite")225 class MySuite:226 def __init__(self):227 add_test_into_suite(lcc.Test("mytest", "My Test", func), self)228 suite = load_suite_from_class(MySuite)229 assert len(suite.get_tests()) == 1230def test_add_test_into_suite_with_function_and_fixture():231 def func(fixt):232 pass233 @lcc.suite("My Suite")234 class MySuite:235 def __init__(self):236 add_test_into_suite(lcc.Test("mytest", "My Test", func), self)237 suite = load_suite_from_class(MySuite)238 assert suite.get_tests()[0].get_fixtures() == ["fixt"]239def test_add_test_into_suite_with_method():240 @lcc.suite("My Suite")241 class MySuite:242 def __init__(self):243 add_test_into_suite(lcc.Test("mytest", "My Test", self.func), self)244 def func(self):245 pass246 suite = load_suite_from_class(MySuite)247 assert len(suite.get_tests()) == 1248def test_add_test_into_suite_with_method_and_fixture():249 @lcc.suite("My Suite")250 class MySuite:251 def __init__(self):252 add_test_into_suite(lcc.Test("mytest", "My Test", self.func), self)253 def func(self, fixt):254 pass255 suite = load_suite_from_class(MySuite)256 assert suite.get_tests()[0].get_fixtures() == ["fixt"]257def test_add_test_into_suite_with_callable():258 class SomeTest(object):259 def __call__(self):260 pass261 @lcc.suite("My Suite")262 class MySuite:263 def __init__(self):264 add_test_into_suite(lcc.Test("mytest", "My Test", SomeTest()), self)265 suite = load_suite_from_class(MySuite)266 assert len(suite.get_tests()) == 1267def test_add_test_into_suite_with_callable_and_fixture():268 class SomeTest(object):269 def __call__(self, fixt):270 pass271 @lcc.suite("My Suite")272 class MySuite:273 def __init__(self):274 add_test_into_suite(lcc.Test("mytest", "My Test", SomeTest()), self)275 suite = load_suite_from_class(MySuite)276 assert suite.get_tests()[0].get_fixtures() == ["fixt"]277def test_add_test_into_suite_multiple():278 @lcc.suite("My Suite")279 class MySuite:280 def __init__(self):281 for i in 1, 2, 3:282 add_test_into_suite(lcc.Test("mytest_%d" % i, "My Test %d" % i, dummy_test_callback()), self)283 suite = load_suite_from_class(MySuite)284 assert len(suite.get_tests()) == 3285def test_add_test_into_suite_disabled():286 @lcc.suite("My Suite")287 class MySuite:288 def __init__(self):289 test = lcc.Test("mytest", "My Test", dummy_test_callback())290 test.disabled = True291 add_test_into_suite(test, self)292 suite = load_suite_from_class(MySuite)293 test = suite.get_tests()[0]294 assert test.is_disabled()295def test_add_test_into_module():296 suite = build_suite_from_module("""297import sys298def func():299 pass300lcc.add_test_into_suite(lcc.Test("test", "Test", func), sys.modules[__name__])301""")302 assert len(suite.get_tests()) == 1303def test_get_fixtures():304 @lcc.suite("My Suite")305 class MySuite:306 def setup_suite(self, foo):307 pass308 suite = load_suite_from_class(MySuite)309 assert suite.get_fixtures() == ["foo"]310def test_depends_on_test():311 @lcc.suite("suite")312 class suite:313 @lcc.test("My Test")314 @lcc.depends_on("another.test")315 def test(self):316 pass317 suite = load_suite_from_class(suite)318 test = suite.get_tests()[0]319 assert test.dependencies == ["another.test"]320def test_depends_on_suite():321 with pytest.raises(AssertionError):322 @lcc.suite("suite")323 @lcc.depends_on("another.suite")324 class suite:325 @lcc.test("My Test")326 def test(self):...
test_testtree.py
Source:test_testtree.py
...7 class mysuite:8 @lcc.test("My test")9 def mytest(self):10 pass11 suite = load_suite_from_class(mysuite)12 test = suite.get_tests()[0]13 path = test.hierarchy14 assert next(path).name == "mysuite"15 assert next(path).name == "mytest"16def test_get_path_on_nested_suite():17 @lcc.suite("My suite")18 class mysuite:19 @lcc.suite("My sub suite")20 class mysubsuite:21 @lcc.test("My test")22 def mytest(self):23 pass24 suite = load_suite_from_class(mysuite)25 test = suite.get_suites()[0].get_tests()[0]26 path = test.hierarchy27 assert next(path).name == "mysuite"28 assert next(path).name == "mysubsuite"29 assert next(path).name == "mytest"30def test_hierarchy_depth():31 @lcc.suite("My suite")32 class mysuite:33 @lcc.test("My test")34 def mytest(self):35 pass36 suite = load_suite_from_class(mysuite)37 test = suite.get_tests()[0]38 assert test.hierarchy_depth == 139def test_path():40 @lcc.suite("My suite")41 class mysuite:42 @lcc.test("My test")43 def mytest(self):44 pass45 suite = load_suite_from_class(mysuite)46 test = suite.get_tests()[0]47 assert test.path == "mysuite.mytest"48def test_hierarchy_tags():49 @lcc.tags("tag1")50 @lcc.suite("MySuite")51 class MySuite:52 @lcc.suite("MySubSuite")53 class MySubSuite:54 @lcc.tags("tag2")55 @lcc.test("Test 2")56 def test(self):57 pass58 suite = load_suite_from_class(MySuite)59 assert suite.get_suites()[0].get_tests()[0].hierarchy_tags == ["tag1", "tag2"]60def test_hierarchy_properties():61 @lcc.prop("prop1", "foo")62 @lcc.prop("prop2", "bar")63 @lcc.suite("MySuite")64 class MySuite:65 @lcc.prop("prop3", "foobar")66 @lcc.suite("MySubSuite")67 class MySubSuite:68 @lcc.prop("prop1", "baz")69 @lcc.test("Test 2")70 def test(self):71 pass72 suite = load_suite_from_class(MySuite)73 assert suite.get_suites()[0].get_tests()[0].hierarchy_properties == {"prop1": "baz", "prop2": "bar", "prop3": "foobar"}74def test_hierarchy_links():75 @lcc.link("http://www.example.com/1234")76 @lcc.suite("MySuite")77 class MySuite:78 @lcc.suite("MySubSuite")79 class MySubSuite:80 @lcc.link("http://www.example.com/1235", "#1235")81 @lcc.test("Test 2")82 def test(self):83 pass84 suite = load_suite_from_class(MySuite)85 assert suite.get_suites()[0].get_tests()[0].hierarchy_links == [("http://www.example.com/1234", None), ("http://www.example.com/1235", "#1235")]86def test_hierarchy_paths():87 @lcc.suite("MySuite")88 class MySuite:89 @lcc.suite("MySubSuite")90 class MySubSuite:91 @lcc.test("Test 2")92 def test(self):93 pass94 suite = load_suite_from_class(MySuite)95 assert list(suite.get_suites()[0].get_tests()[0].hierarchy_paths) == ["MySuite", "MySuite.MySubSuite", "MySuite.MySubSuite.test"]96def test_hierarchy_descriptions():97 @lcc.suite("My suite")98 class MySuite:99 @lcc.suite("My sub suite")100 class MySubSuite:101 @lcc.test("Test")102 def test(self):103 pass104 suite = load_suite_from_class(MySuite)105 assert list(suite.get_suites()[0].get_tests()[0].hierarchy_descriptions) == ["My suite", "My sub suite", "Test"]106def test_flatten_suites():107 @lcc.suite("My suite 1")108 class mysuite1:109 @lcc.test("Test 1")110 def test1(self):111 pass112 @lcc.suite("My suite 2")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")232 class mysuite2:233 @lcc.test("My test")234 def mytest(self):235 pass236 suite = load_suite_from_class(mysuite1)237 assert not suite.is_empty()238def test_is_empty_on_suite_without_test():239 @lcc.suite("My suite 1")240 class mysuite1:241 pass242 suite = load_suite_from_class(mysuite1)243 assert suite.is_empty()244def test_pull_test_node():245 @lcc.suite("My suite 1")246 class mysuite1:247 @lcc.test("My test")248 def mytest(self):249 pass250 suite = load_suite_from_class(mysuite1)251 test = suite.get_tests()[0]252 pulled_test = test.pull_node()253 assert pulled_test.parent_suite is None254 assert test.parent_suite is not None255def test_pull_test_suite_top():256 @lcc.suite("My suite 1")257 class mysuite1:258 @lcc.test("My test")259 def mytest(self):260 pass261 suite = load_suite_from_class(mysuite1)262 pulled_suite = suite.pull_node()263 assert pulled_suite.parent_suite is None264 assert len(pulled_suite.get_tests()) == 0265 assert suite.parent_suite is None266 assert len(suite.get_tests()) == 1267def test_pull_test_suite():268 @lcc.suite("My suite 1")269 class mysuite1:270 @lcc.suite("My suite 2")271 class mysuite2:272 @lcc.test("My test")273 def mytest(self):274 pass275 top_suite = load_suite_from_class(mysuite1)276 sub_suite = top_suite.get_suites()[0]277 pulled_suite = sub_suite.pull_node()278 assert pulled_suite.parent_suite is None279 assert len(pulled_suite.get_tests()) == 0280 assert sub_suite.parent_suite is not None...
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!!