pytest-dev / pyfakefs

Provides a fake file system that mocks the Python file system modules.
https://pytest-pyfakefs.readthedocs.io
Apache License 2.0
627 stars 88 forks source link

additional_skip_names is ignored for Path().open #1012

Closed sassanh closed 1 month ago

sassanh commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Thanks! It is working for me.