pytest运行报错:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xaf in position 82: illegal multibyte

pytest运行报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xaf in position 82: illegal multibyte sequence

 

 

复制代码
D:\Python\environment\python3.9.7\python3.exe D:/Python/nas_autotest/run.py
Traceback (most recent call last):
  File "D:\Python\nas_autotest\run.py", line 15, in <module>
    pytest.main(["--junitxml=reports/results.xml"])  # 用例生成执行统计结果
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "D:\Python\environment\python3.9.7\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1157, in _preparse
    self._initini(args)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\__init__.py", line 1076, in _initini
    rootpath, inipath, inicfg = determine_setup(
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 184, in determine_setup
    rootdir, inipath, inicfg = locate_config([ancestor])
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 106, in locate_config
    ini_config = load_config_dict_from_file(p)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 45, in load_config_dict_from_file
    iniconfig = _parse_ini_config(filepath)
  File "D:\Python\environment\python3.9.7\lib\site-packages\_pytest\config\findpaths.py", line 30, in _parse_ini_config
    return iniconfig.IniConfig(str(path))
  File "D:\Python\environment\python3.9.7\lib\site-packages\iniconfig\__init__.py", line 54, in __init__
    tokens = self._parse(iter(f))
  File "D:\Python\environment\python3.9.7\lib\site-packages\iniconfig\__init__.py", line 82, in _parse
    for lineno, line in enumerate(line_iter):
UnicodeDecodeError: 'gbk' codec can't decode byte 0x8d in position 590: illegal multibyte sequence

Process finished with exit code 1
复制代码

解决方式:
第一种:
将pytest.ini文件中的中文字符串去掉

如果需要保留中文备注,则使用第二种方法:
点击报错内容倒数第二个

File "D:\Python\environment\python3.9.7\lib\site-packages\iniconfig\__init__.py", line 54, in __init__
    tokens = self._parse(iter(f))

这个文件 在52行吧当前的文件打开方式添加上 'utf-8'的解码方式

 

f = open(self.path,encoding='utf-8')

 

posted @   陈晓猛  阅读(52)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-06-03 使用Postman工具做接口测试(五)——生成随机参数
2021-06-03 使用Postman工具做接口测试(四)——参数化、执行用例与生成测试报告(完结篇)
2021-06-03 使用Postman工具做接口测试(三)——断言与参数提取
2021-06-03 使用Postman工具做基本测试(二)环境变量和请求参数格式
2021-06-03 使用Postman工具做接口测试(一)安装基本功能介绍和简单使用
2021-06-03 <unittest>
2021-06-03 $(document).on和$('#idname').on和$(function(){ })区别
点击右上角即可分享
微信分享提示