How to use get_fixture_dependencies method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

fixture.py

Source:fixture.py Github

copy

Full Screen

...181 for fixture in fixtures:182 self.add_fixture(fixture)183 def get_fixture(self, name):184 return self._fixtures[name]185 def get_fixture_dependencies(self, name, ref_fixtures=()):186 fixture_params = [p for p in self._fixtures[name].params if p != "fixture_name"]187 if any(ref_fixture in fixture_params for ref_fixture in ref_fixtures):188 raise FixtureConstraintViolation(189 "Fixture params %s have circular dependency on a fixture among %s" % (fixture_params, ref_fixtures)190 )191 dependencies = OrderedSet()192 for param in fixture_params:193 if param not in self._fixtures:194 raise FixtureConstraintViolation("Fixture '%s' used by fixture '%s' does not exist" % (param, name))195 dependencies.update(self.get_fixture_dependencies(param, (name,) + ref_fixtures))196 dependencies.update(fixture_params)197 return dependencies198 def check_dependencies(self):199 """200 Checks for:201 - missing dependencies202 - circular dependencies203 - scope incoherence204 - forbidden fixture name205 raises FixtureConstraintViolation if a check fails206 """207 # first, check for forbidden fixture name208 for fixture_name in self._fixtures.keys():209 if fixture_name in _FORBIDDEN_FIXTURE_NAMES:210 raise FixtureConstraintViolation("Fixture name '%s' is forbidden" % fixture_name)211 # second, check for missing & circular dependencies212 for fixture_name in self._fixtures.keys():213 self.get_fixture_dependencies(fixture_name)214 # third, check fixture compliance with their direct fixture dependencies215 for fixture in self._fixtures.values():216 dependency_fixtures = [self._fixtures[param] for param in fixture.params if param != "fixture_name"]217 for dependency_fixture in dependency_fixtures:218 if dependency_fixture.per_thread and fixture.scope != "test":219 raise FixtureConstraintViolation(220 "Fixture '%s' with scope '%s' is incompatible with per-thread fixture '%s'" % (221 fixture.name, fixture.scope, dependency_fixture.name222 )223 )224 if dependency_fixture.scope_level < fixture.scope_level:225 raise FixtureConstraintViolation(226 "Fixture '%s' with scope '%s' is incompatible with scope '%s' of fixture '%s'" % (227 fixture.name, fixture.scope, dependency_fixture.scope, dependency_fixture.name228 )229 )230 def check_fixtures_in_test(self, test):231 for fixture in test.get_fixtures():232 if fixture not in self._fixtures:233 raise FixtureConstraintViolation("Unknown fixture '%s' used in test '%s'" % (fixture, test.path))234 def check_fixtures_in_suite(self, suite):235 for fixture_name in suite.get_fixtures():236 try:237 fixture = self._fixtures[fixture_name]238 except KeyError:239 raise FixtureConstraintViolation("Suite '%s' uses an unknown fixture '%s'" % (suite.path, fixture_name))240 if fixture.per_thread:241 raise FixtureConstraintViolation(242 "Suite '%s' uses per-thread fixture '%s' which is not allowed" % (243 suite.path, fixture.name244 )245 )246 if fixture.scope_level < _SCOPE_LEVELS["suite"]:247 raise FixtureConstraintViolation("Suite '%s' uses fixture '%s' which has an incompatible scope" % (248 suite.path, fixture.name249 ))250 for test in suite.get_tests():251 self.check_fixtures_in_test(test)252 for sub_suite in suite.get_suites():253 self.check_fixtures_in_suite(sub_suite)254 def check_fixtures_in_suites(self, suites):255 for suite in suites:256 self.check_fixtures_in_suite(suite)257 def get_fixture_scope(self, name):258 return self._fixtures[name].scope259 @staticmethod260 def get_fixtures_used_in_suite(suite, include_disabled):261 if not suite.has_enabled_tests() and not include_disabled:262 return OrderedSet()263 fixtures = suite.get_fixtures()264 for test in suite.get_tests():265 if test.is_enabled() or include_disabled:266 fixtures.update(test.get_fixtures())267 return fixtures268 @staticmethod269 def get_fixtures_used_in_suite_recursively(suite, include_disabled):270 fixtures = FixtureRegistry.get_fixtures_used_in_suite(suite, include_disabled)271 for sub_suite in suite.get_suites():272 fixtures.update(FixtureRegistry.get_fixtures_used_in_suite_recursively(sub_suite, include_disabled))273 return fixtures274 def get_scheduled_fixtures_for_scope(self, direct_fixtures, scope, parent_scheduled_fixtures=None):275 fixtures = OrderedSet()276 for fixture in direct_fixtures:277 fixtures.update(self.get_fixture_dependencies(fixture))278 fixtures.add(fixture)279 return ScheduledFixtures(280 scope, [self._fixtures[name] for name in fixtures if self._fixtures[name].scope == scope],281 parent_scheduled_fixtures=parent_scheduled_fixtures282 )283 def get_fixtures_scheduled_for_pre_run(self, suites, include_disabled=False):284 fixtures = OrderedSet()285 for suite in suites:286 fixtures.update(FixtureRegistry.get_fixtures_used_in_suite_recursively(suite, include_disabled))287 return self.get_scheduled_fixtures_for_scope(fixtures, "pre_run")288 def get_fixtures_scheduled_for_session(self, suites, prerun_session_scheduled_fixtures, include_disabled=False):289 fixtures = OrderedSet()290 for suite in suites:291 fixtures.update(FixtureRegistry.get_fixtures_used_in_suite_recursively(suite, include_disabled))...

Full Screen

Full Screen

test_fixtures.py

Source:test_fixtures.py Github

copy

Full Screen

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

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