pytest-dev / pyfakefs

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

additional_skip_names are not respected everywhere in pathlib #1023

Closed sassanh closed 1 month ago

sassanh commented 4 months ago

Describe the bug

Path().exists and Path().unlink for example don't work well with additional_skip_names.

Context: https://github.com/pytest-dev/pyfakefs/issues/1021#issuecomment-2132637499

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.

sassanh commented 4 months ago

and ugly (using the callstack)

I would probably implement it by checking the call stack too, as the final solution. Actually I think checking the call stack is better than module patching, because a Path object may be imported in another module (not listed in skipped modules) and passed to as an argument to a function in this module, module patching wouldn't work well and one would require hacks like this: https://github.com/sassanh/python-redux/blob/main/redux_pytest/fixtures/snapshot.py#L92

Do you have a scenario in head for which checking call stack would cause trouble/unexpected behavior.

mrbean-bremen commented 4 months ago

Do you have a scenario in head for which checking call stack would cause trouble/unexpected behavior.

Probably not. I just didn't like it much, but you may be right.

mrbean-bremen commented 4 months ago

I had that (using the callstack) in mind to use for all functions, but thought that there should be a better way. But as I wrote, this didn't work out. So, you are probably right that this is the way to go - I was just reluctant as I find it somewhat hacky. And with the callstack, you could just do it a single place, so it would probably be ok.

I would probably implement it by checking the call stack too, as the final solution.

So, you are going to make another PR? Would be awesome!

sassanh commented 4 months ago

So, you are going to make another PR? Would be awesome!

I will try.