Best Python code snippet using slash
test_log.py
Source:test_log.py
...11 TEST_LOG_BASENAME = 'logger_unittest'12 TEST_LOG_DIR = ROTEST_WORK_DIR13 @classmethod14 def setUpClass(cls):15 cls.core_log_file_path = cls._get_log_file_path(core_log)16 cls.test_log = get_test_logger(cls.TEST_LOG_BASENAME, cls.TEST_LOG_DIR)17 cls.test_log_file_path = cls._get_log_file_path(cls.test_log)18 @classmethod19 def tearDownClass(cls):20 for log_handler in cls.test_log.handlers:21 log_handler.close()22 os.remove(cls.test_log_file_path)23 @staticmethod24 def _get_log_file_path(logger):25 """Return the logger file handler file path."""26 for handler in logger.handlers:27 if hasattr(handler, 'baseFilename'):28 return handler.baseFilename29 def test_core_logger(self):30 """Log in core logger and verify logging occurs in this logger only."""31 with open(self.core_log_file_path, 'r') as core_log_file:32 with open(self.test_log_file_path, 'r') as test_log_file:33 log_msg = '%s TEST_CORE_LOGGER' % time.ctime()34 core_log_file.seek(0, os.SEEK_END)35 test_log_file.seek(0, os.SEEK_END)36 core_log.debug(log_msg)37 core_log_file_content = core_log_file.read()38 test_log_file_content = test_log_file.read()...
log.py
Source:log.py
...3import os4from app import application5def _get_binary_name():6 return os.path.basename(inspect.stack()[-1][1])7def _get_log_file_path(binary=None):8 logfile = application.config.get('LOG_FILE', None)9 logdir = application.config.get('LOG_DIR', None)10 if logfile and not logdir:11 return logfile12 if logfile and logdir:13 return os.path.join(logdir, logfile)14 if logdir:15 binary = binary or _get_binary_name()16 return "{}.log".format(os.path.join(logdir, binary))17 return None18def _get_formatter():19 date_fmt = "%Y-%m-%d %H:%M:%S"20 log_fmt = '%(asctime)s %(levelname)s %(name)s:%(lineno)d %(message)s'21 formatter = logging.Formatter(log_fmt, date_fmt)22 return formatter23def getLogger(name='unknown', version='unknown'):24 log_file = _get_log_file_path()25 formatter = _get_formatter()26 if log_file is None:27 handler = logging.StreamHandler()28 else:29 handler = logging.FileHandler(log_file)30 handler.setFormatter(formatter)31 logger = logging.getLogger(name)32 logger.addHandler(handler)33 if application.config.get('DEBUG', False):34 logger.setLevel(logging.DEBUG)35 elif application.config.get('VERBOSE', False):36 logger.setLevel(logging.INFO)37 else:38 logger.setLevel(logging.WARNING)...
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!!