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

Error importing module is not properly treated in pytest (fails with UnicodeEncodeError from pytest) #2336

Closed
fabioz opened this Issue Mar 29, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@fabioz
Contributor

fabioz commented Mar 29, 2017

pytest version: 3.0.5, OS: Windows 10, python: 2.7.12

We have an intermittent issue when running pytest in that a module won't be properly loaded when imported by pytest. I still don't know the real reason for the issue (could be pytest related or not, still unsure as it's flaky on our ci)... anyways, the known problem on pytest is that pytest hides the real error by giving an UnicodeEncodeError instead of printing the original message (the error is below).

It seems that the problem is that it's mixing bytes and unicode on python 2:

formatted_tb = py._builtin._totext(exc_repr) # unicode on python 2, and the .format() call is made on a bytes array.

Exception given by pytest:

W:\py27-win64\lib\site-packages\_pytest\runner.py:163: in __init__
    self.result = func()
W:\py27-win64\lib\site-packages\_pytest\main.py:464: in _memocollect
    return self._memoizedcall('_collected', lambda: list(self.collect()))
W:\py27-win64\lib\site-packages\_pytest\main.py:335: in _memoizedcall
    res = function()
W:\py27-win64\lib\site-packages\_pytest\main.py:464: in <lambda>
    return self._memoizedcall('_collected', lambda: list(self.collect()))
W:\py27-win64\lib\site-packages\_pytest\python.py:411: in collect
    self.session._fixturemanager.parsefactories(self)
W:\py27-win64\lib\site-packages\_pytest\fixtures.py:1064: in parsefactories
    holderobj = node_or_obj.obj
W:\py27-win64\lib\site-packages\_pytest\python.py:215: in fget
    self._obj = obj = self._getobj()
W:\py27-win64\lib\site-packages\_pytest\python.py:408: in _getobj
    return self._memoizedcall('_obj', self._importtestmodule)
W:\py27-win64\lib\site-packages\_pytest\main.py:335: in _memoizedcall
    res = function()
W:\py27-win64\lib\site-packages\_pytest\python.py:445: in _importtestmodule
    "{traceback}".format(fspath=self.fspath, traceback=formatted_tb)
E   UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 110: ordinal not in range(128)

@fabioz fabioz changed the title from Error importing module is not properly treated in pytest to Error importing module is not properly treated in pytest (fails with UnicodeEncodeError from pytest) Mar 29, 2017

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Mar 29, 2017

@fabioz thanks for reporting this one so swiftly and detailed, this one has to be fixed before doing the 3.1 release

@The-Compiler

This comment has been minimized.

Member

The-Compiler commented Mar 29, 2017

Can you try with 3.0.7?

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Mar 29, 2017

at first glance, master is the same

@nicoddemus nicoddemus self-assigned this Mar 29, 2017

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Mar 29, 2017

I'm on it 👍

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Mar 29, 2017

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Mar 29, 2017

This was referenced Mar 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment