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

pyfakefs cannot fake open calls if module has specific names #708

Closed
marnanel opened this issue Aug 30, 2022 · 4 comments · Fixed by #712
Closed

pyfakefs cannot fake open calls if module has specific names #708

marnanel opened this issue Aug 30, 2022 · 4 comments · Fixed by #712

Comments

@marnanel
Copy link

Describe the bug

If a module under test has a name listed in FakeIoModule.skip_names, then open calls are never faked.

For example, one of these names is io.py. Issue #569 solved the same problem for names ending with that string, such as logsio.py. But a submodule within any package may reasonably have the exact name io.py, and this will trigger the behaviour nonetheless.

How To Reproduce

Example code is in https://github.com/marnanel/pyfakefs-issue . Running the test in that repo gets you a FileNotFoundError when the code in wombat.io attempts to access the file created in the fake filesystem by the test.

Environment

Linux-5.10.0-16-amd64-x86_64-with-glibc2.31
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110]
pyfakefs 4.5.4
@marnanel
Copy link
Author

The workaround is

open.__self__.skip_names.remove('io')

where "io" is the name of the module that's causing the trouble.

@mrbean-bremen
Copy link
Member

Thanks - that is indeed a shortcoming of pyfakefs, it just never came up before. I think it is a valid use case and we see how this can be avoided (probably by skipping modules not solely based on their name).
I'm not sure when I will get to it - currently short on free time, and also have a couple of other things to finish - by I will look into it.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Sep 3, 2022
- allows using own modules with the same name
- fixes pytest-dev#708
mrbean-bremen added a commit that referenced this issue Sep 4, 2022
- allows using own modules with the same name
- fixes #708
github-actions bot pushed a commit that referenced this issue Sep 4, 2022
@mrbean-bremen
Copy link
Member

@marnanel - should be fixed in master now - please check if it works for you!

@marnanel
Copy link
Author

marnanel commented Sep 8, 2022

Working fine here. Thanks for the fast response!

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

Successfully merging a pull request may close this issue.

2 participants