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

additional_skip_names is ignored for Path().open #1012

Closed
sassanh opened this issue May 6, 2024 · 2 comments · Fixed by #1015
Closed

additional_skip_names is ignored for Path().open #1012

sassanh opened this issue May 6, 2024 · 2 comments · Fixed by #1015
Labels

Comments

@sassanh
Copy link
Contributor

sassanh commented May 6, 2024

Describe the bug
I noticed additional_skip_names works for builtin open, io.open and os.open but it doesn't work for Path().open unless I add pathlib to additional_skip_names too. I guess it is because Path.open itself is not monitored and io.open is monitored instead as Path.open uses io.open internally.

How To Reproduce

This works:

with Patcher(
    additional_skip_names=[
        'pathlib',
    ],
) as patcher:
    if patcher.fs:
      from x import x
      x()

x.py

def x():
  print(Path('some_path').open('r').read())

But this doesn't work:

with Patcher(
    additional_skip_names=[
        'x',
    ],
) as patcher:
    if patcher.fs:
      from x import x
      x()

x.py

def x():
  print(Path('some_path').open('r').read())

Your environment
macOS-14.4.1-arm64-arm-64bit
Python 3.11.9 (main, Apr 2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)]
pyfakefs 5.4.1
pytest 8.2.0

@mrbean-bremen
Copy link
Member

Sorry, I first mis-read the issue (deleted that answer, in case you saw it).

additional_skip_names is indeed tricky, and I remember having problems to get it to work with pathlib. I will have a closer look later, hopefully there is an easy fix (though I doubt it).

@sassanh
Copy link
Contributor Author

sassanh commented May 12, 2024

Thanks! It is working for me.

sassanh added a commit to sassanh/pyfakefs that referenced this issue May 26, 2024
mrbean-bremen pushed a commit that referenced this issue May 26, 2024
…text and write_bytes (#1022)

* Add more regression tests for #1012
* Resolve pytype errors by adding __enter__, __exit__, read and write to file wrappers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants