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

Path.exists is not patched #1021

Closed
sassanh opened this issue May 22, 2024 · 7 comments
Closed

Path.exists is not patched #1021

sassanh opened this issue May 22, 2024 · 7 comments

Comments

@sassanh
Copy link
Contributor

sassanh commented May 22, 2024

Describe the bug
I call Path().exists immediately after shutil.copyfile and it returns False while os.path.exists returns True.
I guess Path().exists is using the real filesystem.

How To Reproduce

Path('/tmp/test').write_text('test')
print(Path('/tmp/test').exists())
print(os.path.exists('/tmp/test'))

Your environment

macOS-14.5-arm64-arm-64bit
Python 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
pyfakefs 5.5.0
pytest 8.2.1
@sassanh
Copy link
Contributor Author

sassanh commented May 22, 2024

I also noticed Path().unlink doesn't work (maybe it is working on the real filesystem) while os.remove works.

@mrbean-bremen
Copy link
Member

Can you please show how you call that code? E.g. a reproducible example, if possible.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented May 23, 2024

For illustration - the following test passes:

def test_fakefs(fs):
    fs.os = OSType.LINUX
    path = Path('/tmp/test')
    path.parent.mkdir(exist_ok=True)
    path.touch()
    path.write_text('test')
    assert path.exists()
    assert os.path.exists('/tmp/test')
    path.unlink()
    assert not path.exists()

So you must be doing something different.

@sassanh
Copy link
Contributor Author

sassanh commented May 24, 2024

Thanks for investigating it! I probably did something wrong, I will check it when I get back to my desk.

In the future I will add reproduction snippets with my reports.

@sassanh
Copy link
Contributor Author

sassanh commented May 26, 2024

It was an issue on my side, I had pathlib in additional_skip_names from the past 🙈
I will make sure to create simple reproduction steps before reporting any issues in the future.

@sassanh sassanh closed this as completed May 26, 2024
@sassanh
Copy link
Contributor Author

sassanh commented May 26, 2024

@mrbean-bremen Quick question, are Path().exists and Path().unlink expected to respect additional_skip_names?

sassanh added a commit to sassanh/python-redux that referenced this issue May 27, 2024
…y`/`except` instead of checking `Path().exists()` as `pyfakefs` doesn't seem to respect `skip_names` for `Path().exists()`

relevant: pytest-dev/pyfakefs#1021 (comment)
sassanh added a commit to sassanh/python-redux that referenced this issue May 27, 2024
…y`/`except` instead of checking `Path().exists()` as `pyfakefs` doesn't seem to respect `skip_names` for `Path().exists()`

relevant: pytest-dev/pyfakefs#1021 (comment)
sassanh added a commit to sassanh/python-redux that referenced this issue May 27, 2024
…y`/`except` instead of checking `Path().exists()` as `pyfakefs` doesn't seem to respect `skip_names` for `Path().exists()`

relevant: pytest-dev/pyfakefs#1021 (comment)
@mrbean-bremen
Copy link
Member

Well... I had hoped you won't ask :)

The truth is that I did want to implement a more generic solution for the handling of additional_skip_names in pathlib, but couldn't get it to work. The current implementation is incomplete (yes, actually all methods should respect additional_skip_names) and ugly (using the callstack). I had hoped that it will sufficient until I get back to it, but obviously I was wrong.

Feel free to write a new issue. Maybe you even have an idea on how to implement this in a better way...

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

No branches or pull requests

2 participants