Best Python code snippet using Airtest
Decorators.py
Source:Decorators.py
...45# print('display function ran')46#47#48# @decorator_function49# def display_info(name, age):50# print('display_info ran with arguments ({}, {})'.format(name, age))51#52#53# display_info('John', 25)54# display()55#56# def decorator_function(original_function):57# def wrapper_function(*args, **kwargs):58# print('wrapper executed this before {}'.format(original_function.__name__))59# return original_function(*args, **kwargs)60# return wrapper_function61# class decorator_class(object):62# def __init__(self, original_function):63# self.original_function = original_function64#65# def __call__(self, *args, **kwargs):66# print('call method executed this before {}'.format(self.original_function.__name__))67# return self.original_function(*args, **kwargs)68#69#70# @decorator_class71# def display():72# print('display function ran')73#74#75# @decorator_class76# def display_info(name, age):77# print('display_info ran with arguments ({}, {})'.format(name, age))78#79#80# display_info('John', 25)81# display()82import time83def my_logger(orig_func):84 import logging85 logging.basicConfig(filename='{}.log'.format(orig_func.__name__), level=logging.INFO)86 def wrapper(*args, **kwargs):87 logging.info(88 'Ran with args: {}, and kwargs: {}'.format(args, kwargs))89 return orig_func(*args, **kwargs)90 return wrapper91def my_timer(orig_func):92 import time93 def wrapper(*args, **kwargs):94 t1 = time.time()95 result = orig_func(*args, **kwargs)96 t2 = time.time() - t197 print('{} ran in: {} sec'.format(orig_func.__name__, t2))98 return result99 return wrapper100# @my_logger101# @my_timer102# def display_info(name, age):103# time.sleep(1)104# print('display_info ran with arguments ({}, {})'.format(name, age))105#106#107# display_info('Hank', 30)108# @my_logger109def display_info(name, age):110 print('display_info ran with arguments ({}, {})'.format(name, age))111display_info = my_timer(my_timer(display_info))...
decorator_with_arguments.py
Source:decorator_with_arguments.py
...8 return result9 return wrapper_function10 return decorator_function11@prefix_decorator('TESTING:')12def display_info(name, age):13 print(f'display_info ran with arguments ({name}, {age})')14display_info('Developer', 18)15display_info('Administrator', 25)16def display_info(name, age):17 print(f'display_info ran with arguments ({name}, {age})')18# display_info = prefix_decorator('TRYING:')(display_info)19# display_info('Administrator', 25)20# display_info_func = prefix_decorator('DISPLAY:')21# display_info = display_info_func(display_info)...
app.py
Source:app.py
...8# @decorator_class9# def display():10# print('display function ran')11# @decorator_class12# def display_info(name, age):13# print(f'display_info ran with arguments ({name}, {age})')14# display_info('developer', 18)15# display()16def display():17 print('display function ran')18def display_info(name, age):19 print(f'display_info ran with arguments ({name}, {age})')20display = decorator_class(display)21display()22display_info = decorator_class(display_info)...
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!!