使用 pytest 时出现错误 OSError: [WinError 87] 参数不正确

使用 pytest 时出现错误 OSError: [WinError 87] 参数不正确

我已经安装了 pytest 但是在命令提示符中测试 pytest --version 时出现以下错误:

Traceback (most recent call last):

File "C:\Python\Scripts\pytest-script.py", line 11, in <module>

load_entry_point('pytest==5.1.0', 'console_scripts', 'pytest')()

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\config\__init__.py", line 58, in main

config = _prepareconfig(args, plugins)

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\config\__init__.py", line 208, in _prepareconfig

pluginmanager=pluginmanager, args=args

File "c:\python\lib\site-packages\pluggy\hooks.py", line 289, in __call__

return self._hookexec(self, self.get_hookimpls(), kwargs)

File "c:\python\lib\site-packages\pluggy\manager.py", line 87, in _hookexec

return self._inner_hookexec(hook, methods, kwargs)

File "c:\python\lib\site-packages\pluggy\manager.py", line 81, in <lambda>

firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,

File "c:\python\lib\site-packages\pluggy\callers.py", line 203, in _multicall

gen.send(outcome)

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\helpconfig.py", line 89, in pytest_cmdline_parse

config = outcome.get_result()

File "c:\python\lib\site-packages\pluggy\callers.py", line 80, in get_result

raise ex[1].with_traceback(ex[2])

File "c:\python\lib\site-packages\pluggy\callers.py", line 187, in _multicall

res = hook_impl.function(*args)

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\config\__init__.py", line 716, in pytest_cmdline_parse

self.parse(args)

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\config\__init__.py", line 924, in parse

self._preparse(args, addopts=addopts)

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\config\__init__.py", line 880, in _preparse

early_config=self, args=args, parser=self._parser

File "c:\python\lib\site-packages\pluggy\hooks.py", line 289, in __call__

return self._hookexec(self, self.get_hookimpls(), kwargs)

File "c:\python\lib\site-packages\pluggy\manager.py", line 87, in _hookexec

return self._inner_hookexec(hook, methods, kwargs)

File "c:\python\lib\site-packages\pluggy\manager.py", line 81, in <lambda>

firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,

File "c:\python\lib\site-packages\pluggy\callers.py", line 208, in _multicall

return outcome.get_result()

File "c:\python\lib\site-packages\pluggy\callers.py", line 80, in get_result

raise ex[1].with_traceback(ex[2])

File "c:\python\lib\site-packages\pluggy\callers.py", line 182, in _multicall

next(gen) # first yield

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\capture.py", line 42, in pytest_load_initial_conftests

_py36_windowsconsoleio_workaround(sys.stdout)

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\capture.py", line 819, in _py36_windowsconsoleio_workaround

sys.stdin = _reopen_stdio(sys.stdin, "rb")

File "c:\python\lib\site-packages\pytest-5.1.0-py3.7.egg\_pytest\capture.py", line 812, in _reopen_stdio

open(os.dup(f.fileno()), mode, buffering),

OSError: [WinError 87] The parameter is incorrect

我该如何修复它?

答案1

看起来这是由于 pytest/Python 错误造成的:

https://github.com/pytest-dev/pytest/issues/5724

https://bugs.python.org/issue37549

目前,您可以降级到 Python 3.7.3,直到有人找到解决方法。

相关内容