在使用hook编辑脚本的时候,没有添加任何读取文件操作,报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xa1 in position 15: illegal multibyte sequence

conftest.py文件
from typing import Optional

def pytest_runtest_setup(item: “Item”) → None:
print(“hook :setup”)

def pytest_runtest_teardown(item: “Item”, nextitem: Optional[“Item”]) → None:
print(“hook:tesrdown”)

test_hook.py文件:

def test_dmone1():
print("test nhook fanfan ")

报错信息:

D:\工作文件\自动化\huogewiozi_test\pytest_test\fixture>pytest test_hook.py
Traceback (most recent call last):
File “e:\python\lib\runpy.py”, line 193, in run_module_as_main
main”, mod_spec)
File “e:\python\lib\runpy.py”, line 85, in run_code
exec(code, run_globals)
File "E:\python\Scripts\pytest.exe_main
.py", line 7, in
File "e:\python\lib\site-packages_pytest\config_init
.py", line 185, in console_main
code = main()
File “e:\python\lib\site-packages_pytest\config_init_.py”, line 143, in main
config = prepareconfig(args, plugins)
File "e:\python\lib\site-packages_pytest\config_init
.py", line 319, in _prepareconfig
pluginmanager=pluginmanager, args=args
File “e:\python\lib\site-packages\pluggy\hooks.py”, line 286, in call
return self._hookexec(self, self.get_hookimpls(), kwargs)
File “e:\python\lib\site-packages\pluggy\manager.py”, line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File “e:\python\lib\site-packages\pluggy\manager.py”, line 87, in
firstresult=hook.spec.opts.get(“firstresult”) if hook.spec else False,
File “e:\python\lib\site-packages\pluggy\callers.py”, line 203, in multicall
gen.send(outcome)
File “e:\python\lib\site-packages_pytest\helpconfig.py”, line 100, in pytest_cmdline_parse
config: Config = outcome.get_result()
File “e:\python\lib\site-packages\pluggy\callers.py”, line 80, in get_result
raise ex[1].with_traceback(ex[2])
File “e:\python\lib\site-packages\pluggy\callers.py”, line 187, in multicall
res = hook_impl.function(*args)
File "e:\python\lib\site-packages_pytest\config_init
.py", line 1003, in pytest_cmdline_parse
self.parse(args)
File "e:\python\lib\site-packages_pytest\config_init
.py", line 1283, in parse
self.preparse(args, addopts=addopts)
File "e:\python\lib\site-packages_pytest\config_init
.py", line 1157, in _preparse
self.initini(args)
File "e:\python\lib\site-packages_pytest\config_init
.py", line 1080, in _initini
config=self,
File “e:\python\lib\site-packages_pytest\config\findpaths.py”, line 184, in determine_setup
rootdir, inipath, inicfg = locate_config([ancestor])
File “e:\python\lib\site-packages_pytest\config\findpaths.py”, line 106, in locate_config
ini_config = load_config_dict_from_file(p)
File “e:\python\lib\site-packages_pytest\config\findpaths.py”, line 45, in load_config_dict_from_file
iniconfig = _parse_ini_config(filepath)
File “e:\python\lib\site-packages_pytest\config\findpaths.py”, line 30, in parse_ini_config
return iniconfig.IniConfig(str(path))
File "e:\python\lib\site-packages\iniconfig_init
.py", line 54, in init
tokens = self.parse(iter(f))
File "e:\python\lib\site-packages\iniconfig_init
.py", line 82, in _parse
for lineno, line in enumerate(line_iter):
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa1 in position 15: illegal multibyte sequence

你的pytest.ini文件里有中文吧

关闭