pytest failed to run on windows: OSError: [WinError 87]

Created on 10 Aug 2019  ·  17Comments  ·  Source: pytest-dev/pytest

I'm using a clean virtual env on windows 7 with python 3.7.4, the pytest is always failed with a OSError as below, on the same machine, i have succeeded to run the pytest on same code with a previou python version, is this related to an upgrade with python?

(calculator) D:\workspace\CalculatorLibrary>pytest -h
Traceback (most recent call last):
  File "d:\python37\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python37\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\workspace\calculator\Scripts\pytest.exe\__main__.py", line 9, in <module>
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 55, in main
    config = _prepareconfig(args, plugins)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 200, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "d:\workspace\calculator\lib\site-packages\pluggy\hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 203, in _multicall
    gen.send(outcome)
  File "d:\workspace\calculator\lib\site-packages\_pytest\helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 661, in pytest_cmdline_parse
    self.parse(args)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 869, in parse
    self._preparse(args, addopts=addopts)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 825, in _preparse
    early_config=self, args=args, parser=self._parser
  File "d:\workspace\calculator\lib\site-packages\pluggy\hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 208, in _multicall
    return outcome.get_result()
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 182, in _multicall
    next(gen)  # first yield
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 42, in pytest_load_initial_conftests
    _py36_windowsconsoleio_workaround(sys.stdout)
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 815, in _py36_windowsconsoleio_workaround
    sys.stdin = _reopen_stdio(sys.stdin, "rb")
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 808, in _reopen_stdio
    open(os.dup(f.fileno()), mode, buffering),
OSError: [WinError 87] 参数错误。
windows needs information

Most helpful comment

I have reinstalled to use python 3.7.3, and everything works just fine, it seems a compatibility issue between python 3.7.4 and pytest.

All 17 comments

Strange. Is there any chance of you editing the capture.py file shown in the traceback and commenting out the call to _py36_windowsconsoleio_workaround?

Strange. Is there any chance of you editing the capture.py file shown in the traceback and commenting out the call to _py36_windowsconsoleio_workaround?

I've tried to comment out the call to '_py36_windowsconsoleio_workaround(sys.stdout)', and another expection occurred

if ns.capture == "fd":
        pass
        #_py36_windowsconsoleio_workaround(sys.stdout)

errors captured:

(calculator) D:\workspace>pytest -h
Traceback (most recent call last):
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 200, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "d:\workspace\calculator\lib\site-packages\pluggy\hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 203, in _multicall
    gen.send(outcome)
  File "d:\workspace\calculator\lib\site-packages\_pytest\helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 661, in pytest_cmdline_parse
    self.parse(args)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 869, in parse
    self._preparse(args, addopts=addopts)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 825, in _preparse
    early_config=self, args=args, parser=self._parser
  File "d:\workspace\calculator\lib\site-packages\pluggy\hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "d:\workspace\calculator\lib\site-packages\pluggy\manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "d:\workspace\calculator\lib\site-packages\pluggy\callers.py", line 203, in _multicall
    gen.send(outcome)
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 56, in pytest_load_initial_conftests
    capman.suspend_global_capture()
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 130, in suspend_global_capture
    cap.suspend_capturing(in_=in_)
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 492, in suspend_capturing
    self.out.suspend()
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 600, in suspend
    self.syscapture.suspend()
AttributeError: 'FDCapture' object has no attribute 'syscapture'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python37\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python37\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\workspace\calculator\Scripts\pytest.exe\__main__.py", line 9, in <module>
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 55, in main
    config = _prepareconfig(args, plugins)
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 203, in _prepareconfig
    config._ensure_unconfigure()
  File "d:\workspace\calculator\lib\site-packages\_pytest\config\__init__.py", line 654, in _ensure_unconfigure
    fin()
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 117, in stop_global_capturing
    self._global_capturing.pop_outerr_to_orig()
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 482, in pop_outerr_to_orig
    out, err = self.readouterr()
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 524, in readouterr
    self.out.snap() if self.out is not None else "",
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 625, in snap
    res = super().snap()
  File "d:\workspace\calculator\lib\site-packages\_pytest\capture.py", line 583, in snap
    self.tmpfile.seek(0)
AttributeError: 'FDCapture' object has no attribute 'tmpfile'

I have reinstalled to use python 3.7.3, and everything works just fine, it seems a compatibility issue between python 3.7.4 and pytest.

Thanks!

That's really strange. I've just installed python 3.7.4 here on Windows and pytest -h works fine for me.

Can you translate what OSError: [WinError 87] 参数错误。 means? Also, are you using 32 or 64-bit Python? You can check the banner for that information:

λ python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Can you translate what OSError: [WinError 87] 参数错误。 means?

Or I can use Google Translate, duh. It means "Parameter error". Hmm...

Looks like https://bugs.python.org/issue37549 - it only happens on Windows 7 (not Windows 10) which might explain why @nicoddemus can't reproduce it.

Oh sorry, I've missed that important bit of information. Thanks Florian!

Woot, merged to 3.7 branch:

https://github.com/python/cpython/pull/15438

So this will be fixed by upstream 3.7.5 it seems.

Closing this for now given that this was fixed upstream. 👍

Although this is pytest-dev github repo, I would like to highlight that you get the same error even when not testing. I am using a venv and was just reading data from a socket connection.

@rahul-ki Indeed! "OSError: [WinError 87] The parameter is incorrect." boils down to "Python called some function in the Windows API, and Windows thinks that it was called the wrong way" - there's a lot of reasons why that can happen.

Windows 10, python 3.8.1, pytest 5.3.3 (same 5.3.4) = INTERNALERROR> OSError: [WinError 87]

platform win32 -- Python 3.8.1, pytest-5.3.3, py-1.8.1, pluggy-0.13.1 -- C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.8.1', 'Platform': 'Windows-10-10.0.17134-SP0', 'Packages': {'pytest': '5.3.3', 'py': '1.8.1', 'pluggy': '0.13.1'}, 'Plugins': {'forked': '1.1.3', 'html': '2.0.1', 'metadata': '1.8.0', 'rerunfailures': '8.0', 'splinter': '2.0.1', 'xdist': '1.31.0'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_201'}
rootdir: C:\Users\gkazarkin\Desktop\Code\GOp\qa, inifile: pytest.ini
plugins: forked-1.1.3, html-2.0.1, metadata-1.8.0, rerunfailures-8.0, splinter-2.0.1, xdist-1.31.0
gw0 I / gw1 I / gw2 I / gw3 I / gw4 I
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\_pytest\main.py", line 194, in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\xdist\dsession.py", line 78, in pytest_sessionstart
INTERNALERROR>     nodes = self.nodemanager.setup_nodes(putevent=self.queue.put)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\xdist\workermanage.py", line 64, in setup_nodes
INTERNALERROR>     nodes.append(self.setup_node(spec, putevent))
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\xdist\workermanage.py", line 68, in setup_node
INTERNALERROR>     gw = self.group.makegateway(spec)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\execnet\multi.py", line 133, in makegateway
INTERNALERROR>     io = gateway_io.create_io(spec, execmodel=self.execmodel)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\execnet\gateway_io.py", line 118, in create_io
INTERNALERROR>     return Popen2IOMaster(args, execmodel)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\execnet\gateway_io.py", line 21, in __init__
INTERNALERROR>     self.popen = p = execmodel.PopenPiped(args)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\site-packages\execnet\gateway_base.py", line 184, in PopenPiped
INTERNALERROR>     return self.subprocess.Popen(args, stdout=PIPE, stdin=PIPE)
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
INTERNALERROR>     self._execute_child(args, executable, preexec_fn, close_fds,
INTERNALERROR>   File "C:\Users\gkazarkin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
INTERNALERROR>     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
INTERNALERROR> OSError: [WinError 87]

works until pytest/4.6.9/ or lower
since 5.0.0+ = OSError: [WinError 87]

@gkazarkin thats a ydist/execnet issue unrelated to the orginal issue, please open a new one

windows 7
pytest 5.4.1
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32

Got the problem OSError: [WinError 87]
Set environment variable PYTHONLEGACYWINDOWSSTDIO and the error changed for:

```Traceback (most recent call last):
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\config__init__.py", line 258, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\manager.py", line 87, in
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\callers.py", line 203, in _multicall
gen.send(outcome)
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\helpconfig.py", line 90, in pytest_cmdline_parse
config = outcome.get_result()
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\config__init__.py", line 836, in pytest_cmdline_parse
self.parse(args)
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\config__init__.py", line 1044, in parse
self._preparse(args, addopts=addopts)
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\config__init__.py", line 1002, in _preparse
early_config=self, args=args, parser=self._parser
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\manager.py", line 87, in
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "c:\work\git\productiongenerator\venv\lib\site-packages\pluggy\callers.py", line 203, in _multicall
gen.send(outcome)
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 68, in pytest_load_initial_conftests
capman.suspend_global_capture()
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 142, in suspend_global_capture
cap.suspend_capturing(in_=in_)
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 484, in suspend_capturing
self.out.suspend()
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 602, in suspend
self.syscapture.suspend()
AttributeError: 'FDCapture' object has no attribute 'syscapture'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\guifran001appdata\local\programs\python\python37Lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\guifran001appdata\local\programs\python\python37Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\work\git\productiongenerator\venv\Scripts\pytest.exe__main__.py", line 7, in
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\config__init__.py", line 105, in main
config = _prepareconfig(args, plugins)
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\config__init__.py", line 261, in _prepareconfig
config._ensure_unconfigure()
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytest\config__init__.py", line 829, in _ensure_unconfigure

fin()

File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 129, in stop_global_capturing
self._global_capturing.pop_outerr_to_orig()
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 474, in pop_outerr_to_orig
out, err = self.readouterr()
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 515, in readouterr
out = self.out.snap()
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 628, in snap
res = super().snap()
File "c:\work\git\productiongenerator\venv\lib\site-packages_pytestcapture.py", line 585, in snap
self.tmpfile.seek(0)
AttributeError: 'FDCapture' object has no attribute 'tmpfile'
```

Where is solution??

Was this page helpful?
0 / 5 - 0 ratings