unittest运行问题

长期更新

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值