UnicodeEncodeError on source files containing non-ascii characters#4074
UnicodeEncodeError on source files containing non-ascii characters#4074spg wants to merge 2 commits intopytest-dev:masterfrom
Conversation
… non-ascii characters
| if astnode is None: | ||
| content = str(source) | ||
| if six.PY2: | ||
| content = unicode(source) |
There was a problem hiding this comment.
Unfortunately this still might fail, because unicode will try to use the ascii codec to decode the bytestream (see py27 failure). Not sure if by this point getstatementrange_ast shouldn't already be a unicode stream actually. 🤔
|
Your original reproduction does not reproduce for me: Can you list all of your currently installed dependencies? I suspect something suspicious is afoot |
|
@asottile Yes you are right, I created a fresh virtualenv (Python 2.7.14), and like you said, the problem is not happening. |
|
@spg could you list the deps in your (broken) venv so we can triage what package is doing nefarious things? |
|
Here is the output from |
|
I have been able to reproduce the issue with a fresh venv and by installing the following packages: pytest (latest), |
|
I have narrowed down the venv even further. I can reproduce the issue by installing only: |
|
I swear, it's going to be the number of week-hours of developer time I've lost to that thing. |
|
ok yep, it's a bug in pyfakefs -- I'll look on making a PR there |
|
Here's that PR, with that applied the example works again: pytest-dev/pyfakefs#441 Thanks again for the issue and reproduction steps, this was paramount to finding the root cause! 🎉 |
|
Thanks for the fix! I applied your patch locally, and it all works now! 🎉 |
`python-future` is notorious for breaking modules which use `try:` / `except:` to import modules based on version. In this case, `pyfakefs` imported the backported `builtins` module which changes the semantics of the `open()` function. `pyfakefs` then monkeypatches `linecache` which breaks any module which attempts to use `linecache` (in this case `pytest`). The downstream issue is pytest-dev/pytest#4074
This PR fixes an issue I had when running tests that:
Here's an example of such a test (
test_bug.py):Running this test outputs the following:
Aside from the obvious stacktrace, you can see that pytest reported that 0 tests ran.
With my fix:
I'm not sure if or how I should write a test for this particular case. Any help is appreciated.