How to use __fixture_decorator_factory method in Testify

Best Python code snippet using Testify_python

test_fixtures.py

Source:test_fixtures.py Github

copy

Full Screen

...277 return function278 return mark_test_with_suites279# unique id for fixtures280_fixture_id = [0]281def __fixture_decorator_factory(fixture_type):282 """Decorator generator for the fixture decorators.283 Tagging a class/instancemethod as 'setup', etc, will mark the method with a284 _fixture_id. Smaller fixture ids correspond to functions higher on the285 class hierarchy, since base classes (and their methods!) are created before286 their children.287 When our test cases are instantiated, they use this _fixture_id to sort288 methods into the appropriate _fixture_methods bucket. Note that this289 sorting cannot be done here, because this decorator does not recieve290 instancemethods -- which would be aware of their class -- because the class291 they belong to has not yet been created.292 **NOTE**: This means fixtures of the same type on a class will be executed293 in the order that they are defined, before/after fixtures execute on the294 parent class execute setups/teardowns, respectively.295 """296 def fixture_decorator(callable_):297 # Decorators act on *functions*, so we need to take care when dynamically298 # decorating class attributes (which are (un)bound methods).299 function = inspection.get_function(callable_)300 # record the fixture type and id for this function301 function._fixture_type = fixture_type302 if function.__name__ in DEPRECATED_FIXTURE_TYPE_MAP:303 # we push deprecated setUps/tearDowns to the beginning or end of304 # our fixture lists, respectively. this is the best we can do,305 # because these methods are generated in the order their classes306 # are created, so we can't assign a fair fixture_id to them.307 function._fixture_id = 0 if fixture_type.endswith('setup') else float('inf')308 else:309 # however, if we've tagged a fixture with our decorators then we310 # effectively register their place on the class hierarchy by this311 # fixture_id.312 function._fixture_id = _fixture_id[0]313 _fixture_id[0] += 1314 return function315 fixture_decorator.__name__ = fixture_type316 return fixture_decorator317class_setup = __fixture_decorator_factory('class_setup')318setup = __fixture_decorator_factory('setup')319teardown = __fixture_decorator_factory('teardown')320class_teardown = __fixture_decorator_factory('class_teardown')321setup_teardown = __fixture_decorator_factory('setup_teardown')322class_setup_teardown = __fixture_decorator_factory('class_setup_teardown')323class let(object):324 """Decorator that creates a lazy-evaluated helper property. The value is325 cached across multiple calls in the same test, but not across multiple326 tests.327 """328 _unsaved = []329 def __init__(self, func):330 self._func = func331 self._result = self._unsaved332 def __get__(self, test_case, cls):333 if test_case is None:334 return self335 if self._result is self._unsaved:336 self.__set__(test_case, self._func(test_case))...

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