搭建框架过程中遇到不少了问题,有些没有记录,先把记录下来的几个问题放上
问题1:
Traceback (most recent call last):
File "D:\tollsinstall\selenium2024\TFLearnPython\TFTEST2\run.py", line 6, in <module>
from utils.logger import get_logger
File "D:\tollsinstall\selenium2024\TFLearnPython\TFTEST2\utils\logger.py", line 9, in <module>
config.read(os.path.join(os.path.dirname(__file__),'../config/logger.ini'))
File "D:\tollsinstall\selenium2024\python311\Lib\configparser.py", line 714, in read
self._read(fp, filename)
File "D:\tollsinstall\selenium2024\python311\Lib\configparser.py", line 1037, in _read
for lineno, line in enumerate(fp, start=1):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 37: illegal multibyte sequence
解决方案:
with open(filename, encoding=encoding) as fp: 改为
with open(filename, encoding=‘UTF-8’) as fp:即可
原文链接:https://www.cnblogs.com/lxc1997ye/p/11665400.html
问题2:
D:\tollsinstall\selenium2024\python311\python.exe D:\tollsinstall\selenium2024\TFLearnPython\TFTEST2\run.py
Traceback (most recent call last):
File "D:\tollsinstall\selenium2024\TFLearnPython\TFTEST2\run.py", line 6, in <module>
from utils.logger import get_logger
File "D:\tollsinstall\selenium2024\TFLearnPython\TFTEST2\utils\logger.py", line 11, in <module>
logger.add(config.get('handler_fileHandler','class'), level=config.get('logger_root','level'), rotation=config.getint('handler_fileHandler','args')[2], retention=config.getint('handler_fileHandler','args')[3])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\tollsinstall\selenium2024\python311\Lib\configparser.py", line 835, in getint
return self._get_conv(section, option, int, raw=raw, vars=vars,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\tollsinstall\selenium2024\python311\Lib\configparser.py", line 825, in _get_conv
return self._get(section, conv, option, raw=raw, vars=vars,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\tollsinstall\selenium2024\python311\Lib\configparser.py", line 820, in _get
return conv(self.get(section, option, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: "('logs/test.log','D',1,30)"
原因:这个错误是由于在尝试将字符串 ('logs/test.log','D',1,30) 转换为整数时出现了 ValueError,因为这个字符串不是一个有效的整数表示形式。
rotation = int(config.get('handler_fileHandler', 'args').split(',')[2].strip(')'))
retention = int(config.get('handler_fileHandler', 'args').split(',')[3].strip(')'))
这样修改后,代码会先获取 'handler_fileHandler' 部分的 'args' 参数,然后使用 split() 方法按逗号进行分割,并从中提取索引为 2 和 3 的值作为 rotation 和 retention。最后使用 int() 将其转换为整数。
问题3:
D:\tollsinstall\selenium2024\python311\python.exe D:\tollsinstall\selenium2024\TFLearnPython\TFTEST2\run.py
2024-03-05 11:32:01.313 | INFO | __main__:<module>:12 - Start testing...
Traceback (most recent call last):
File "D:\tollsinstall\selenium2024\TFLearnPython\TFTEST2\run.py", line 17, in <module>
runner.run(suite)
^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'run'
原因:
runner 对象为 NoneType,因此无法调用 run 方法导致 AttributeError;不返回任何内容的函数;原因可能是没有读取到HTMLTestRunner 方法;
检查有没有安装HTMLTestRunner 模块,如果没有
步骤一:可以手动下载 HTMLTestRunner.py 文件,
http://tungwaiyip.info/software/HTMLTestRunner.html
步骤二:把下载好的HTMLTestRunner.py放入Python/Lib目录下;
步骤四:官网上下载的HTMLTestRuner.py是python2语法写的,此处要改成python3语法
第94行,将import StringIO修改成import io
第539行,将self.outputBuffer = StringIO.StringIO()修改成self.outputBuffer = io.StringIO()
第642行,将if not rmap.has_key(cls):修改成if not cls in rmap:
第766行,将uo = o.decode('latin-1')修改成uo = e
第772行,将ue = e.decode('latin-1')修改成ue = e
第775行,将ue = e.decode('latin-1')修改成ue = e
第631行,将print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime))
原文出处:https://blog.csdn.net/adonis_lu37/article/details/82692191
修改后重新运行成功: