Skip to content

Commit 51781b9

Browse files
asottilemrbean-bremen
authored andcommitted
Fix pytest when pyfakefs + future is installed
`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
1 parent 1886f92 commit 51781b9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pyfakefs/pytest_plugin.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ def my_fakefs_test(fs):
1010
"""
1111

1212
import linecache
13+
import sys
1314

1415
import py
1516
import pytest
1617

1718
from pyfakefs.fake_filesystem_unittest import Patcher
1819

19-
try:
20+
if sys.version_info >= (3,):
2021
import builtins
21-
except ImportError:
22+
else:
2223
import __builtin__ as builtins
2324

2425
Patcher.SKIPMODULES.add(py) # Ignore pytest components when faking filesystem

0 commit comments

Comments
 (0)