Skip to content

Error with console output in Python 3.6 on Windows #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wheerd opened this issue Dec 21, 2016 · 26 comments
Closed

Error with console output in Python 3.6 on Windows #103

wheerd opened this issue Dec 21, 2016 · 26 comments

Comments

@wheerd
Copy link

wheerd commented Dec 21, 2016

When running pytest in Python 3.6rc2 on Windows, there seems to be a problem with formatting the console output. The tests run fine until at some point it crashes because of a OSError: [WinError 87] The parameter is incorrect. This does not happen if I pipe the output into a file instead of having it in the console. I am not sure whether that is an issue with the py._io.TerminalWriter or something else. Since the 3.6 version is also not stable yet, so the issue might be there.

This is the trace back I am getting:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\_pytest\main.py", line 98, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "C:\Program Files\Python36\lib\site-packages\_pytest\main.py", line 133, in _main
    config.hook.pytest_runtestloop(session=session)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\main.py", line 154, in pytest_runtestloop
    item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 254, in _wrapped_call
    return call_outcome.get_result()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 279, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 265, in __init__
    self.result = func()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\runner.py", line 66, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\runner.py", line 79, in runtestprotocol
    reports.append(call_and_report(item, "call", log))
  File "C:\Program Files\Python36\lib\site-packages\_pytest\runner.py", line 137, in call_and_report
    hook.pytest_runtest_logreport(report=report)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\terminal.py", line 207, in pytest_runtest_logreport
    self.write_fspath_result(rep.nodeid, letter)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\terminal.py", line 123, in write_fspath_result
    self._tw.write(res)
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 207, in write
    write_out(self._file, markupmsg)
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 342, in write_out
    fil.write(msg)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 175, in write_plain_text
    self.wrapped.flush()
OSError: [WinError 87] The parameter is incorrect

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\_pytest\main.py", line 111, in wrap_session
    config.notify_exception(excinfo, config.option)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\config.py", line 923, in notify_exception
    excinfo=excinfo)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\terminal.py", line 164, in pytest_internalerror
    self.write_line("INTERNALERROR> " + line)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\terminal.py", line 145, in write_line
    self.ensure_newline()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\terminal.py", line 136, in ensure_newline
    self._tw.line()
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 212, in line
    self.write('\n')
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 207, in write
    write_out(self._file, markupmsg)
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 342, in write_out
    fil.write(msg)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
OSError: [WinError 87] The parameter is incorrect

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python36\lib\site-packages\pytest.py", line 17, in <module>
    raise SystemExit(pytest.main())
  File "C:\Program Files\Python36\lib\site-packages\_pytest\config.py", line 57, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\main.py", line 127, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\main.py", line 122, in wrap_session
    exitstatus=session.exitstatus)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "C:\Program Files\Python36\lib\site-packages\_pytest\terminal.py", line 359, in pytest_sessionfinish
    self._tw.line("")
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 212, in line
    self.write('\n')
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 207, in write
    write_out(self._file, markupmsg)
  File "C:\Program Files\Python36\lib\site-packages\py\_io\terminalwriter.py", line 342, in write_out
    fil.write(msg)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
OSError: [WinError 87] The parameter is incorrect
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
OSError: [WinError 87] The parameter is incorrect
@qdamian
Copy link

qdamian commented Jan 1, 2017

+1. The same happens to me, with pytest 3.0.5, python 3.6.0 release (= RC 2) on Windows 8

@WiliTest
Copy link

WiliTest commented Jan 8, 2017

same error in windows 7 with python36: when using read() or readlines() to read the content of a file.txt containing UTF8 characters

path=r"C:\Users\test.txt"
text= open(giomTXT_path, "r")
a= text.readlines()
print(a)
text.close()

a= text.readlines()
Python35: works with or without UTF8 (in the file read).
Python 36: works with ansi char but doesn't if the file read contain UTF8. I get this error:

OSError: [WinError 87] The parameter is incorrect
Exception ignored in: <_io.TextIOWrapper name='' mode='w' encoding='utf-
8'>
OSError: [WinError 87] The parameter is incorrect

a= text.read()
Python36: no error with ansi but UTF8 give that error:

OSError: [WinError 87] The parameter is incorrect
Exception ignored in: <_io.TextIOWrapper name='' mode='w' encoding='utf-
8'>
OSError: [WinError 87] The parameter is incorrect

@gboeing
Copy link

gboeing commented Mar 1, 2017

Same error on Windows 10 with Python 3.6.0.final.0 when trying to print to the console. This previously had worked fine in Python 3.5.

@RonnyPfannschmidt
Copy link
Member

this looks like python 3.6 broke colorama - at first glace i believe tartley/colorama#121 needs to get merged and released

@RonnyPfannschmidt
Copy link
Member

a potential workaround may be to uninstall colorama, can a windows user verify if that holds up?

@gboeing
Copy link

gboeing commented Mar 1, 2017

I just uninstalled colorama and tried to re-run my tests, but got the same error as before.

@wheerd
Copy link
Author

wheerd commented Mar 1, 2017

My current workaround is piping the output into a file as that avoids the error.
Uninstalling colorama didn't work for me either.

@lsternlicht
Copy link

+1 with 3.6.0 & Windows Server 2016

@pkch
Copy link

pkch commented May 25, 2017

Same error with 3.6.1 & Windows 10 Education build 14393. And just like @gboeing , when I uninstalled colorama, the error did not disappear.

@pkch
Copy link

pkch commented May 25, 2017

Note that the error occurs even though pytest is not attempting to print any non-ASCII characters (in fact, the particular character on which this happens is a dot). Can anyone replicate this reliably without pytest?

@segevfiner
Copy link
Contributor

I tried to debug this horror. It wasn't pretty... 😭

The error really originates from _io._WindowsConsoleIO.write (built-in/native method) and the real error is masked by some weird error handling code in that function (Modules/_io/winconsoleio.c:1002-1016). You instead get ERROR_INVALID_PARAMETER (87) from passing a 0 sized buffer to WideCharToMultiByte in that error handling code when WriteConsoleW fails.

The real error appears to be ERROR_INVALID_HANDLE from WriteConsoleW, this makes me suspicious that the real culprit isn't colorama but something else that causes the console handle opened by _io._WindowsConsoleIO to be randomly closed. So I placed a breakpoint on CloseHandle and lo and behold! CloseHandle does get called on that console handle by dup2 likely called by Pytest's FDCapture.

But why in the world would it only close it randomly?! Despite calling CloseHandle on it multiple times. Does that console handle have some weird randomized ref count or something... (Uninitialized memory? 😝). But handles don't really have ref counts... only the underlying objects do and it's actually the number of handles they have (or kernel references too but never mind that...).

Anyhow... What I think is the real issue here is that now Python is writing directly to an HANDLE and not to an msvcrt file descriptor and if the dup2 call somehow clobbers the underlying HANDLE that Python is using we get foobared.

Yet I still don't understand why it's random... 😕

Also note issue on colorama: tartley/colorama#119

@pkch
Copy link

pkch commented Jun 1, 2017

I'm not sure where the code for dup2 is in CPython; I guess windows doesn't have it natively, so it's here perhaps https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Python/dup2.c? If the native Windows fd duplication is used, it's probably this: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724251(v=vs.85).aspx which does seem to use refcounts.

@segevfiner
Copy link
Contributor

@pkch I think it's this posixmodule.c:7822-7835.

It might be calling the msvcrt/ucrt dup2 (Maybe with an underscore) you can see it's code in the ucrt sources in the Windows SDK. I might check later if it's really this one.

@segevfiner
Copy link
Contributor

Setting PYTHONLEGACYWINDOWSSTDIO made the tests pass. Well except test_fdopen_kept_alive_issue124 which crashed/terminated the test process 😫.

segevfiner added a commit to segevfiner/pytest that referenced this issue Jun 2, 2017
Python 3.6 implemented unicode console handling for Windows. This works
by reading/writing to the raw console handle using
``{Read,Write}ConsoleW``.

The problem is that we are going to ``dup2`` over the stdio file
descriptors when doing ``FDCapture`` and this will ``CloseHandle`` the
handles used by Python to write to the console. Though there is still some
weirdness and the console handle seems to only be closed randomly and not
on the first call to ``CloseHandle``, or maybe it gets reopened with the
same handle value when we suspend capturing.

The workaround in this case will reopen stdio with a different fd which
also means a different handle by replicating the logic in
"Py_lifecycle.c:initstdio/create_stdio".

See pytest-dev/py#103
@nicoddemus
Copy link
Member

Fixed by pytest-dev/pytest#2462

@pwaivers
Copy link

pwaivers commented Oct 11, 2017

This is happening to me when I run pytest from the command line with the specs: platform win32 -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0.

Strangely, it only occurs on some of the runs. Sometimes it will fail and throw the giant stack trace, and some times it will succeed just fine. It has NOT occurred when I run in PyCharm however.

@The-Compiler
Copy link
Member

@pwaivers The fix was part of pytest 3.1.2, the latest release is 3.2.3. You might want to upgrade.

@zash121
Copy link

zash121 commented Nov 24, 2018

Solved . !!!!!
same error happen when I tried to open(file).read()
but is solved when I just add encoding = ISO-8859-1.
my code is
data = open('file.json',encoding = 'ISO-8859-1').read()

@nicoddemus
Copy link
Member

Thanks for following up

@oholimoli
Copy link

Hi,

I'm using a clean Python 3.7 installation on Windows 7 and get this WinError 87 :(

C:\Users\hofo\Desktop\test>python --version
Python 3.7.4

C:\Users\hofo\Desktop\test>pip list
Package               Version
--------------------- -------
atomicwrites          1.3.0
attrs                 19.1.0
colorama              0.4.1
importlib-metadata    0.19
more-itertools        7.2.0
packaging             19.1
pip                   19.0.3
pluggy                0.12.0
py                    1.8.0
pyparsing             2.4.2
pytest                5.0.1
setuptools            40.8.0
six                   1.12.0
virtualenv            16.7.2
virtualenvwrapper-win 1.2.5
wcwidth               0.1.7
zipp                  0.5.2
You are using pip version 19.0.3, however version 19.2.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

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

C:\Users\hofo\Desktop\test>

@siben168
Copy link

Hi,

I'm using a clean Python 3.7 installation on Windows 7 and get this WinError 87 :(

C:\Users\hofo\Desktop\test>python --version
Python 3.7.4

C:\Users\hofo\Desktop\test>pip list
Package               Version
--------------------- -------
atomicwrites          1.3.0
attrs                 19.1.0
colorama              0.4.1
importlib-metadata    0.19
more-itertools        7.2.0
packaging             19.1
pip                   19.0.3
pluggy                0.12.0
py                    1.8.0
pyparsing             2.4.2
pytest                5.0.1
setuptools            40.8.0
six                   1.12.0
virtualenv            16.7.2
virtualenvwrapper-win 1.2.5
wcwidth               0.1.7
zipp                  0.5.2
You are using pip version 19.0.3, however version 19.2.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

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

C:\Users\hofo\Desktop\test>

I got the same problem with 3.7.4 and pytest clean environment

@blueyed
Copy link
Contributor

blueyed commented Aug 10, 2019

@oholimoli @siben168
It looks more like a problem in pytest, and not py?!
Can you provide more info about the args there?
(e.g. via print(f.fileno(), mode, buffering))

@blueyed
Copy link
Contributor

blueyed commented Aug 10, 2019

According to #103 (comment) it might be due to an encoding issue even.
I suggest filing the issue for pytest, with more information (from the comment above, and possibly uncommon encoding setup).
Also a minimal reproducible example would be good - it is not clear if that happens with a simple test file already.

@siben168
Copy link

According to #103 (comment) it might be due to an encoding issue even.
I suggest filing the issue for pytest, with more information (from the comment above, and possibly uncommon encoding setup).
Also a minimal reproducible example would be good - it is not clear if that happens with a simple test file already.

Yes, this is an issue for pytest, I have submitted an issue for pytest. Thanks!

@mkleehammer
Copy link

It sounds like this issue needs to be reopened. I'm seeing the same thing with a fresh Python 3.7 venv on Windows when I simply run python -m pytest --help and pytest --version.

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

@blueyed
Copy link
Contributor

blueyed commented Aug 12, 2019

=> pytest-dev/pytest#5724

@pytest-dev pytest-dev locked as off-topic and limited conversation to collaborators Aug 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests