How to use load_fixtures_from_func method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

fixture.py

Source:fixture.py Github

copy

Full Screen

...297 def get_fixtures_scheduled_for_test(self, test, suite_scheduled_fixtures):298 return self.get_scheduled_fixtures_for_scope(299 test.get_fixtures(), "test", suite_scheduled_fixtures300 )301def load_fixtures_from_func(func):302 # type: (Callable) -> List[Fixture]303 """304 Load a fixture from a function that has been decorated with ``@lcc.fixture()``305 """306 assert hasattr(func, "_lccfixtureinfo")307 info = func._lccfixtureinfo # noqa308 args = get_callable_args(func)309 return [Fixture(name, func, info.scope, args, info.per_thread) for name in info.names]310def load_fixtures_from_module(mod):311 # type: (Any) -> List[Fixture]312 """313 Load fixtures from a module instance.314 .. versionadded:: 1.5.1315 """316 fixtures = []317 for sym_name in dir(mod):318 sym = getattr(mod, sym_name)319 if hasattr(sym, "_lccfixtureinfo"):320 fixtures.extend(load_fixtures_from_func(sym))321 return fixtures322def load_fixtures_from_file(filename):323 # type: (str) -> List[Fixture]324 """325 Load fixtures from a given file.326 """327 try:328 mod = import_module(filename)329 except ModuleImportError as e:330 raise FixtureLoadingError(str(e))331 return load_fixtures_from_module(mod)332def load_fixtures_from_files(patterns, excluding=[]):333 # type: (Any[str, Sequence[str]], Any[str, Sequence[str]]) -> List[Fixture]334 """...

Full Screen

Full Screen

test_fixtures.py

Source:test_fixtures.py Github

copy

Full Screen

...23def test_load_from_func():24 @lcc.fixture()25 def myfixture():26 pass27 fixtures = load_fixtures_from_func(myfixture)28 assert len(fixtures) == 129 assert fixtures[0].name == "myfixture"30 assert fixtures[0].scope == "test"31 assert len(fixtures[0].params) == 032def test_load_from_func_with_multiple_fixture_names():33 @lcc.fixture(names=["foo", "bar"])34 def myfixture():35 pass36 fixtures = load_fixtures_from_func(myfixture)37 assert len(fixtures) == 238 assert fixtures[0].name == "foo"39 assert fixtures[0].scope == "test"40 assert len(fixtures[0].params) == 041 assert fixtures[1].name == "bar"42 assert fixtures[1].scope == "test"43 assert len(fixtures[1].params) == 044def test_load_from_func_with_parameters():45 @lcc.fixture()46 def myfixture(foo, bar):47 pass48 fixtures = load_fixtures_from_func(myfixture)49 assert len(fixtures) == 150 assert fixtures[0].name == "myfixture"51 assert fixtures[0].scope == "test"52 assert fixtures[0].params == ["foo", "bar"]53def test_execute_fixture():54 @lcc.fixture()55 def myfixture():56 return 4257 fixture = load_fixtures_from_func(myfixture)[0]58 result = fixture.execute({})59 assert result.get() == 4260def test_execute_fixture_builtin():61 fixture = BuiltinFixture("fix", 42)62 result = fixture.execute({})63 assert result.get() == 4264def test_execute_fixture_with_yield():65 @lcc.fixture()66 def myfixture():67 yield 4268 fixture = load_fixtures_from_func(myfixture)[0]69 result = fixture.execute({})70 assert result.get() == 4271def test_teardown_fixture():72 @lcc.fixture()73 def myfixture():74 return 4275 fixture = load_fixtures_from_func(myfixture)[0]76 result = fixture.execute({})77 result.get()78 result.teardown()79def test_teardown_fixture_with_yield():80 flag = []81 @lcc.fixture()82 def myfixture():83 yield 4284 flag.append(True)85 fixture = load_fixtures_from_func(myfixture)[0]86 result = fixture.execute({})87 assert result.get() == 4288 assert not flag89 result.teardown()90 assert flag91def test_execute_fixture_with_parameters():92 @lcc.fixture()93 def myfixture(val):94 return val * 295 fixture = load_fixtures_from_func(myfixture)[0]96 result = fixture.execute({"val": 3})97 assert result.get() == 698def test_get_fixture_result_multiple_times():99 @lcc.fixture()100 def myfixture():101 return 42102 fixture = load_fixtures_from_func(myfixture)[0]103 result = fixture.execute({})104 assert result.get() == 42105 assert result.get() == 42106 assert result.get() == 42107def test_fixture_executed_multiple_times():108 @lcc.fixture()109 def myfixture(val):110 return val * 2111 fixture = load_fixtures_from_func(myfixture)[0]112 result = fixture.execute({"val": 3})113 assert result.get() == 6114 result = fixture.execute({"val": 4})115 assert result.get() == 8116def test_registry_fixture_without_params():117 @lcc.fixture()118 def myfixture():119 return 42120 registry = FixtureRegistry()121 registry.add_fixtures(load_fixtures_from_func(myfixture))122 registry.check_dependencies()123def test_registry_fixture_with_params():124 @lcc.fixture()125 def foo():126 return 21127 @lcc.fixture()128 def bar(foo):129 return foo * 2130 registry = FixtureRegistry()131 registry.add_fixtures(load_fixtures_from_func(foo))132 registry.add_fixtures(load_fixtures_from_func(bar))133 registry.check_dependencies()134def test_registry_fixture_missing_dependency():135 @lcc.fixture()136 def bar(foo):137 return foo * 2138 registry = FixtureRegistry()139 registry.add_fixtures(load_fixtures_from_func(bar))140 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:141 registry.check_dependencies()142 assert "does not exist" in str(excinfo.value)143def test_registry_fixture_circular_dependency_direct():144 @lcc.fixture()145 def foo(bar):146 return bar * 2147 @lcc.fixture()148 def bar(foo):149 return foo * 2150 registry = FixtureRegistry()151 registry.add_fixtures(load_fixtures_from_func(foo))152 registry.add_fixtures(load_fixtures_from_func(bar))153 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:154 registry.get_fixture_dependencies("foo")155 assert 'circular' in str(excinfo.value)156def test_registry_fixture_circular_dependency_indirect():157 @lcc.fixture()158 def baz(foo):159 return foo * 2160 @lcc.fixture()161 def bar(baz):162 return baz * 2163 @lcc.fixture()164 def foo(bar):165 return bar * 2166 registry = FixtureRegistry()167 registry.add_fixtures(load_fixtures_from_func(foo))168 registry.add_fixtures(load_fixtures_from_func(bar))169 registry.add_fixtures(load_fixtures_from_func(baz))170 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:171 registry.get_fixture_dependencies("foo")172 assert 'circular' in str(excinfo.value)173def test_registry_fixture_circular_dependency_indirect_2():174 @lcc.fixture()175 def baz(bar):176 return bar * 2177 @lcc.fixture()178 def bar(baz):179 return baz * 2180 @lcc.fixture()181 def foo(bar):182 return bar * 2183 registry = FixtureRegistry()184 registry.add_fixtures(load_fixtures_from_func(foo))185 registry.add_fixtures(load_fixtures_from_func(bar))186 registry.add_fixtures(load_fixtures_from_func(baz))187 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:188 registry.get_fixture_dependencies("foo")189 assert 'circular' in str(excinfo.value)190def test_registry_fixture_name():191 @lcc.fixture()192 def foo(fixture_name):193 pass194 registry = FixtureRegistry()195 registry.add_fixtures(load_fixtures_from_func(foo))196 registry.check_dependencies()197def test_registry_get_fixture_without_param_dependency():198 @lcc.fixture()199 def foo():200 return 42201 registry = FixtureRegistry()202 registry.add_fixtures(load_fixtures_from_func(foo))203 assert registry.get_fixture_dependencies("foo") == []204def test_registry_get_fixture_with_param_dependency():205 @lcc.fixture()206 def bar():207 return 21208 @lcc.fixture()209 def foo(bar):210 return bar * 2211 registry = FixtureRegistry()212 registry.add_fixtures(load_fixtures_from_func(foo))213 registry.add_fixtures(load_fixtures_from_func(bar))214 assert registry.get_fixture_dependencies("foo") == ["bar"]215def test_registry_get_fixture_with_params_dependency():216 @lcc.fixture()217 def zoub():218 return 21219 @lcc.fixture()220 def baz(zoub):221 return zoub222 @lcc.fixture()223 def bar(baz):224 return baz * 2225 @lcc.fixture()226 def foo(bar, baz):227 return bar * baz228 registry = FixtureRegistry()229 registry.add_fixtures(load_fixtures_from_func(foo))230 registry.add_fixtures(load_fixtures_from_func(bar))231 registry.add_fixtures(load_fixtures_from_func(baz))232 registry.add_fixtures(load_fixtures_from_func(zoub))233 assert registry.get_fixture_dependencies("foo") == ["zoub", "baz", "bar"]234def test_registry_compatible_scope():235 @lcc.fixture(scope="session")236 def bar():237 return 21238 @lcc.fixture(scope="test")239 def foo(bar):240 return bar * 2241 registry = FixtureRegistry()242 registry.add_fixtures(load_fixtures_from_func(foo))243 registry.add_fixtures(load_fixtures_from_func(bar))244 registry.check_dependencies()245def test_registry_incompatible_scope():246 @lcc.fixture(scope="test")247 def bar():248 return 21249 @lcc.fixture(scope="session")250 def foo(bar):251 return bar * 2252 registry = FixtureRegistry()253 registry.add_fixtures(load_fixtures_from_func(foo))254 registry.add_fixtures(load_fixtures_from_func(bar))255 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:256 registry.check_dependencies()257 assert 'incompatible' in str(excinfo.value)258def test_registry_forbidden_fixture_name():259 @lcc.fixture(scope="test")260 def fixture_name():261 return 0262 registry = FixtureRegistry()263 registry.add_fixtures(load_fixtures_from_func(fixture_name))264 with pytest.raises(exceptions.FixtureConstraintViolation) as excinfo:265 registry.check_dependencies()266 assert "forbidden" in str(excinfo.value)267def build_registry():268 @lcc.fixture(scope="pre_run")269 def fix0():270 pass271 @lcc.fixture(scope="session")272 def fix1():273 pass274 @lcc.fixture(scope="suite")275 def fix2():276 pass277 @lcc.fixture(scope="test")278 def fix3():279 pass280 @lcc.fixture(names=["fix4", "fix5"])281 def fix_():282 pass283 registry = FixtureRegistry()284 for func in fix0, fix1, fix2, fix3, fix_:285 registry.add_fixtures(load_fixtures_from_func(func))286 return registry287def test_check_fixtures_in_suites_ok():288 @lcc.suite("MySuite")289 class MySuite:290 @lcc.suite("MySubSuite")291 class MySubSuite:292 @lcc.test("test")293 def sometest(self, fix1):294 pass295 suite = load_suite_from_class(MySuite)296 registry = build_registry()297 registry.check_fixtures_in_suites([suite])298def test_check_fixtures_in_suites_unknown_fixture_in_test():299 @lcc.suite("MySuite")...

Full Screen

Full Screen

test_project.py

Source:test_project.py Github

copy

Full Screen

...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):...

Full Screen

Full Screen

runner.py

Source:runner.py Github

copy

Full Screen

...65 fh.write(fixtures_content)66def build_fixture_registry(*funcs):67 registry = FixtureRegistry()68 for func in funcs:69 registry.add_fixtures(load_fixtures_from_func(func))70 return registry71def run_suites(suites, fixtures=None, backends=None, tmpdir=None, force_disabled=False, stop_on_failure=False,72 report_saving_strategy=None, nb_threads=1):73 if fixtures is None:74 fixture_registry = FixtureRegistry()75 else:76 if isinstance(fixtures, FixtureRegistry):77 fixture_registry = fixtures78 else:79 fixture_registry = build_fixture_registry(*fixtures)80 if backends is None:81 backends = []82 if tmpdir:83 report_dir = tmpdir if isinstance(tmpdir, str) else tmpdir.strpath...

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