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

Regression in >= 3.5.3 when running in python 2.7 #469

Closed
rasjani opened this issue Feb 13, 2019 · 13 comments
Closed

Regression in >= 3.5.3 when running in python 2.7 #469

rasjani opened this issue Feb 13, 2019 · 13 comments
Labels

Comments

@rasjani
Copy link

rasjani commented Feb 13, 2019

builtin data types (and propably something else too) removed (?) after a call to setupPyFakefs() in and after 3.5.3 release with python 2.7.

Run following

from unittest import main as run_tests
import sys

class TestSuites(TestCase):
    def setUp(self):
        self.setUpPyfakefs()
    def test_foo(self):
        real_foo = False

if __name__ == '__main__':
        run_tests(failfast=False, buffer=False, catchbreak=False)

throws following error:

E
======================================================================
ERROR: test_foo (__main__.TestSuites)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_acceptance.py", line 9, in test_foo
NameError: global name 'False' is not defined

----------------------------------------------------------------------
Ran 1 test in 0.009s

FAILED (errors=1)

Same issue doesn't seem to effect python3 with same library version.

Darwin-18.0.0-x86_64-i386-64bit
('Python', '2.7.15 (default, Nov 27 2018, 21:40:55) \n[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]')
('pyfakefs', '3.5.3')

@mrbean-bremen
Copy link
Member

Can you please check with the latest version (3.5.7)? There has been a problem under Python 2.7 in 3.5.3, though it didn't look like this...

@rasjani
Copy link
Author

rasjani commented Feb 13, 2019

Should have been clearer, i did start with 3.5.7 and just rolled back until 3.5.2 that was the newest that was still working..

tl;dr everything in between 3.5.3-3.5.7 fails in python 2.7 ..

@mrbean-bremen
Copy link
Member

Ah, ok - that's unfortunate... I cannot reproduce this, but I don't have a Mac, and the Travis tests run fine on the Mac, so I'm not sure yet how to handle this.
For the time being you may stay on 3.5.2. The main change after that is the one not working for you (automatically patch file system methods imported as another name like from os.path import exists as my_exists). I may have another look at that change - the problem there is that I had to patch __builtin__ under Python 2.7, which seems to be problematic under some conditions and/or systems. Maybe I can make that optional, so that it can be switched off on systems where it doesn't work at least.

@rasjani
Copy link
Author

rasjani commented Feb 13, 2019

Bit of more information: I actually did notice this initially after i added pyfakefs into my project tests in azure that runs on linux/mac/windows with combination of python 2.7 & 3.7. 2.7 tests failed to this same issue on all os's - build here: https://rasjani.visualstudio.com/opensource/_build/results?buildId=219

So, i guess this is not just osx issue ..

@rasjani rasjani changed the title Regression in 3.5.3 when running in python 2.7 Regression in >= 3.5.3 when running in python 2.7 Feb 13, 2019
@mrbean-bremen
Copy link
Member

Ah, thanks - turns out I did a mistake testing this! Instead of running your test using __main__, I used another testrunner (incorrect use of IDE...). I can reproduce this now, so I will have a closer look now.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Feb 13, 2019

Ok, I think I have to re-implement patching __builtins__, maybe using standard mock package (though that would introduce an additional dependency). This may take a while, though...

@rasjani
Copy link
Author

rasjani commented Feb 13, 2019

While im not really that versitile with python internals, the issue seems to be that any old behaviour is not available as globals after builtins is patched. Accessing builtins.False still works, as does builtins._builtin_module.False, so the guestion is, if the class replaces the module, how would one make sure all the class attributes are exposed as globals or is that even possible ?

@mrbean-bremen
Copy link
Member

Yes, I think patching __builtins__ this way was not a good idea. I tried to use the same technique as for patching the other modules, to avoid too much special handling, but I have to rethink this. I will see if I can have another look at the weekend...

@rasjani
Copy link
Author

rasjani commented Feb 14, 2019

That patching happens with py2 only if i read that portion right ? Wouldn’t it be feasible to just del the old open and filesystem and assign your fakes as replacement ?

@mrbean-bremen
Copy link
Member

Yes, something like this. I had some problems with that approach, which I don't remember right now - I wasn't happy with the curretn solution, but it seemed to work. Also I have to check why the unit tests pass that test this behavior - they are obviously not adequate.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Feb 18, 2019
- avoids patching __builtins__ which breaks functionality
- see pytest-dev#469
@mrbean-bremen
Copy link
Member

Ok, I put something together. @rasjani - can you please check if current master works for you?

@rasjani
Copy link
Author

rasjani commented Feb 19, 2019

Appears to work now.

@mrbean-bremen
Copy link
Member

Ok, thanks - I will consider this fixed then. I will probably put together a new release soon, after the other outstanding issues are resolved.
Thanks for the report and the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants