Skip to content
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

pytest issues warning about unicode warnings containign non-ascii even if it only contains ascii chars #2809

Closed
fabioz opened this issue Oct 2, 2017 · 4 comments
Assignees
Labels
plugin: warnings related to the warnings builtin plugin status: critical grave problem or usability issue that affects lots of users type: bug problem that needs to be addressed

Comments

@fabioz
Copy link
Contributor

fabioz commented Oct 2, 2017

pytest: 3.2.1
python: 2.7.12
Windows 10

The test below reproduces the error (the first warning with bytes will work as expected and the second will break pytest).

def test_warnings():
    import warnings
    warnings.warn(b'Something')
    warnings.warn(u'Something')

Error:

============================= test session starts =============================
platform win32 -- Python 2.7.12, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
session-tmp-dir: W:\scbr\Projects\scbr\tmp\tmp-23
rootdir: W:\scbr\Projects\scbr, inifile: pytest.ini
plugins: catchlog-1.2.2, cov-2.5.1, cpp-0.4.4, forked-0.2, localserver-0.3.6, mock-1.6.2, timeout-1.2.0, xdist-1.20.0
collected 1 item

snippet.py .
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\main.py", line 110, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\main.py", line 146, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 614, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\main.py", line 169, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 745, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 339, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 334, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 613, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 254, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 280, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 265, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 613, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\vendored_packages\pluggy.py", line 250, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\warnings.py", line 94, in pytest_runtest_protocol
INTERNALERROR>     yield
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\contextlib.py", line 24, in __exit__
INTERNALERROR>     self.gen.next()
INTERNALERROR>   File "W:\scbr\envs\scbr-py27\lib\site-packages\_pytest\warnings.py", line 88, in catch_warnings_for_item
INTERNALERROR>     UnicodeWarning)
INTERNALERROR> UnicodeWarning: Warning is using unicode non convertible to ascii, converting to a safe representation:
INTERNALERROR>   W:\scbr\Projects\scbr\source\python\snippet.py:5: UserWarning: Something
INTERNALERROR>   warnings.warn(u'Something')
@nicoddemus nicoddemus added plugin: warnings related to the warnings builtin plugin type: bug problem that needs to be addressed labels Oct 2, 2017
@fabioz
Copy link
Contributor Author

fabioz commented Oct 2, 2017

Note: just did some more tests and apparently this error happens only when the PYTHONWARNINGS env variable is set to error::UnicodeWarning::

i.e.:
set PYTHONWARNINGS=error::UnicodeWarning::

Still, note that the unicode passed is convertible to ascii (so, pytest itself should not give a new warning which causes the exception to be raised and gives the internal error).

@nicoddemus nicoddemus added the status: critical grave problem or usability issue that affects lots of users label Oct 2, 2017
@nicoddemus nicoddemus self-assigned this Oct 2, 2017
@nicoddemus
Copy link
Member

Thanks @fabioz!

@nicoddemus nicoddemus changed the title Using warnings.warn with unicode in python 2 breaks pytest with internal error (even if it only contains ascii chars). pytest issues warning about unicode warnings containign non-ascii even if it only contains ascii chars Oct 2, 2017
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Oct 2, 2017
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Oct 2, 2017
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Oct 3, 2017
@bilderbuchi
Copy link
Contributor

@nicoddemus @RonnyPfannschmidt as the #2810 is merged this can be closed I think.

@nicoddemus
Copy link
Member

Yes thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: warnings related to the warnings builtin plugin status: critical grave problem or usability issue that affects lots of users type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants