长期更新
1. 在运行unittest套件的时候提示异常
test_get_order (unittest.loader._FailedTest)
查看日志的时候说我的log,文件有问题,然后重新编辑一下日志保存路径就可以了,代码如下
import time
import os
import logging
path = os.path.dirname(os.path.abspath(__file__)).rsplit("\\", 1)[0]
class LogUtils:
def __init__(self):
self.logfile_path = path + "\logs"
self.logger = logging.getLogger(__name__)
self.logger.setLevel(level=logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')
self.log_name_path = os.path.join(self.logfile_path, "Logs_Test_%s" % time.strftime('%Y_%m_%d'))
self.file_log = logging.FileHandler(self.log_name_path, 'a', encoding='utf-8')
self.file_log.setFormatter(formatter)
self.file_log.setLevel(logging.INFO)
self.logger.addHandler(self.file_log)
self.file_log.close()
self.console = logging.StreamHandler()
self.console.setLevel(logging.INFO)
self.console.setFormatter(formatter)
self.logger.addHandler(self.console)
self.console.close()
def get_log(self):
return self.logger
logger = LogUtils().get_log()
if __name__ == '__main__':
logger.info("hahah")
2. 执行unittest套件时提示一下异常信息
raise NoSectionError(section) from None
configparser.NoSectionError: No section: # 'TEST' 配置分析器无字节TEST,
结合异常报错信息,分析到未读取到ini配置文件中的TEST
这里查询各种资料发现项目中的所有路径都要修改成绝对路径就可以成功运行
path = os.path.dirname(os.path.abspath(__file__))
或者:
path=os.path.dirname(os.path.abspath(__file__)).rsplit("\\",1)[0]
read_ini(path+r"\conf.ini", "TEST", "bbc_url")
3. 运行unittest提示
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
说明浏览器的驱动和浏览器不匹配重新下载驱动即可,放到python.exe同目录
链接地址: https://registry.npmmirror.com/binary.html