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

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
Assignees
Labels
status: critical grave problem or usability issue that affects lots of users type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously

Comments

@fabioz
Copy link
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 Error importing module is not properly treated in pytest Error importing module is not properly treated in pytest (fails with UnicodeEncodeError from pytest) Mar 29, 2017
@RonnyPfannschmidt RonnyPfannschmidt added type: bug problem that needs to be addressed status: critical grave problem or usability issue that affects lots of users type: regression indicates a problem that was introduced in a release which was working previously labels Mar 29, 2017
@RonnyPfannschmidt
Copy link
Member

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

@The-Compiler
Copy link
Member

Can you try with 3.0.7?

@RonnyPfannschmidt
Copy link
Member

at first glance, master is the same

@nicoddemus nicoddemus self-assigned this Mar 29, 2017
@nicoddemus
Copy link
Member

I'm on it 👍

This was referenced Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: critical grave problem or usability issue that affects lots of users type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

4 participants