Getting error with pytest OSError: [WinError 87] The parameter is incorrect

I have installed pytest but getting the following error while testing pytest --version in command prompt:

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

How can I fix it?


Looks like this is due to a pytest/Python bug:

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

https://bugs.python.org/issue37549

For now you could downgrade to Python 3.7.3 until someone finds a workaround.