Best Python code snippet using Airtest
logwraper.py
Source:logwraper.py  
...23        if logfile is None:24            self.logfile = None25            self.logfd = None26        else:27            self.handle_stacked_log()28            self.logfile = os.path.realpath(logfile)29            self.logfd = open(self.logfile, "w")30    @staticmethod31    def _dumper(obj):32        try:33            return obj.__dict__34        except:35            return None36    def log(self, tag, data, in_stack=True):37        ''' Not thread safe '''38        # if self.debug:39        #     print(tag, data)40        LOGGING.debug("%s: %s" % (tag, data))41        if in_stack:42            depth = len(self.running_stack)43        else:44            depth = 145        if self.logfd:46            self.logfd.write(json.dumps({'tag': tag, 'depth': depth, 'time': time.strftime("%Y-%m-%d %H:%M:%S"), 'data': data}, default=self._dumper) + '\n')47            self.logfd.flush()48    def handle_stacked_log(self):49        # å¤çstackä¸çlog50        while self.running_stack:51            # å
åæåä¸ä¸ªï¼è®°äºlogä¹ååpopï¼é¿å
depthé误52            log_stacked = self.running_stack[-1]53            self.log("function", log_stacked)54            self.running_stack.pop()55def Logwrap(f, logger):56    LOGGER = logger57    @functools.wraps(f)58    def wrapper(*args, **kwargs):59        start = time.time()60        fndata = {'name': f.__name__, 'args': args, 'kwargs': kwargs}61        LOGGER.running_stack.append(fndata)62        try:...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!!
