运行pytest报错-UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xb0 in position 26: illegal multiby

如果你在运行pytest时遇到了报错,可能会感到有些困惑和烦恼。

在我的最近学习测试工作中,我遇到了这个错误:UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 26: illegal multibyte sequence。

但是,通过查阅资料和实践,我最终找到了解决方法。

在本篇文章中,我将分享我的经验,讲解为什么会出现这个错误以及如何有效地解决它。

我希望这篇真情实感的文章可以帮助你更好地理解和使用pytest,并且不再被类似的报错所困扰。

错误如下:

D:\pythonproject\AndroidUIauto\Test_App>pytest
Traceback (most recent call last):
  File "d:\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Python\Python37\Scripts\pytest.exe\__main__.py", line 9, in 
  File "d:\python\python37\lib\site-packages\_pytest\config\__init__.py", line 60, in main
    config = _prepareconfig(args, plugins)
  File "d:\python\python37\lib\site-packages\_pytest\config\__init__.py", line 195, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "d:\python\python37\lib\site-packages\pluggy\hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "d:\python\python37\lib\site-packages\pluggy\manager.py", line 68, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "d:\python\python37\lib\site-packages\pluggy\manager.py", line 62, in 
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "d:\python\python37\lib\site-packages\pluggy\callers.py", line 203, in _multicall
    gen.send(outcome)
  File "d:\python\python37\lib\site-packages\_pytest\helpconfig.py", line 93, in pytest_cmdline_parse
    config = outcome.get_result()
  File "d:\python\python37\lib\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "d:\python\python37\lib\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "d:\python\python37\lib\site-packages\_pytest\config\__init__.py", line 654, in pytest_cmdline_parse
    self.parse(args)
  File "d:\python\python37\lib\site-packages\_pytest\config\__init__.py", line 871, in parse
    self._preparse(args, addopts=addopts)
  File "d:\python\python37\lib\site-packages\_pytest\config\__init__.py", line 804, in _preparse
    self._initini(args)
  File "d:\python\python37\lib\site-packages\_pytest\config\__init__.py", line 727, in _initini
    config=self,
  File "d:\python\python37\lib\site-packages\_pytest\config\findpaths.py", line 122, in determine_setup
    rootdir, inifile, inicfg = getcfg([ancestor], config=config)
  File "d:\python\python37\lib\site-packages\_pytest\config\findpaths.py", line 35, in getcfg
    iniconfig = py.iniconfig.IniConfig(p)
  File "d:\python\python37\lib\site-packages\py\_vendored_packages\iniconfig.py", line 54, in __init__
    tokens = self._parse(iter(f))
  File "d:\python\python37\lib\site-packages\py\_vendored_packages\iniconfig.py", line 82, in _parse
    for lineno, line in enumerate(line_iter):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 26: illegal multibyte sequence

解决办法:
更改pytest.ini 文件编码方式为GBK,再次运行不在报错。

运行pytest报错-UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xb0 in position 26: illegal multiby_第1张图片

 原因:
目前未知,不知道具体为什么要这样更改,先记录以便后续跟进。


最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!

在我的QQ技术交流群里(技术交流和资源共享,广告勿扰)

你可能感兴趣的:(软件测试,pytest,自动化测试框架,pytest,软件测试,自动化测试,自动化测试框架,经验分享)