-
Notifications
You must be signed in to change notification settings - Fork 91
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
Inconsistent PurePosixPath / PureWindowsPath behavior #1053
Comments
Thanks - these are always a bit of a pain... I will see what I can do here. |
I can imagine :) would be nice to have. |
Yes - cross-platform testing with pyfakefs will never be perfect, but we can at least try to make it more usable. |
I had a closer look, and I think this is not a bug. As far as I can see, the failing test is class FakePathlibModulePurePathTest(fake_filesystem_unittest.TestCase):
def setUp(self) -> None:
self.setUpPyfakefs()
... it should work. The problem is that the fake pure posix/windows paths need to know the fake filesystem in order to know which system is currently emulated, and what delimiters to use etc., and this is done in the fake filesystem setup. |
Sorry I've uploaded a half cleaned up version of my hacked repro. Maybe my assumption that the the |
Thanks! I couldn't reproduce it yesterday with the changed test, will check again your adapted tests tonight... |
Right, this is the problem. This is a shortcoming of pyfakefs (and any mocking) - if you capture a value in a variable before you start patching, there is no way it can be patched automatically afterwards, except by reloading the module during the test (which is of course not possible if the module is the test). So no, this won't work, and while it is a limitation, I do not consider it a bug. This should not be done in a test, and if done in a module, it can be worked around by adding the module to modules_to_reload. |
Let me refactor this once more, I still think the results for str and
is_absolute differ for the same input in the correctly mocked case and the
default non-mocked case. I presume we should get the same results for the
same inputs?
…On Tue, 27 Aug 2024, 21:27 mrbean-bremen, ***@***.***> wrote:
the key is the capture that original pathlib classes before setting up the
fake FS.
Right, this is the problem. This is a shortcoming of pyfakefs (and any
mocking) - if you capture a value in a variable before you start patching,
there is no way it can be patched automatically afterwards, except by
reloading the module during the test (which is of course not possible if
the module *is* the test).
So no, this won't work, and while it is a limitation, I do not consider it
a bug. This should not be done in a test, and if done in a module, it can
be worked around by adding the module to modules_to_reload
<https://pytest-pyfakefs.readthedocs.io/en/latest/usage.html#modules-to-reload>
.
—
Reply to this email directly, view it on GitHub
<#1053 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA7UDUAGCKLVTV67ICNKPTZTTHL5AVCNFSM6AAAAABNEAGZ3OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJTGM2DMMBSGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sure - as I wrote, emulating another OS is not complete in pyfakefs. There are tests missing, and certainly some bugs hiding. |
You can also just make a real PR with the failing test if you have it, this would make the results for different OSes visible and would be easier to discuss. |
Created PR #1055 |
Thanks for your investigations and PR - that was helpful! I just had a look, and there is indeed a problem. |
Just as an update: this is a bit more complicated than I had hoped, especially in Python >= 3.12, as these versions use the As I wrote elsewhere, I had introduced emulated filesystems as an afterthought for easier testing of This may take a while, so no promises... |
Fixed with #1055 (accidentally put the wrong issue number into the commit message). |
Describe the bug
It seems like
is_absolute
and__str__
don't behave exactly the same betwenpathlib.PureWindowsPath
andpyfakefs.PureWindowsPath
. Likely there are more methods that suffer from the same issue.This is the output of the added tests in
fake_pathlib_test.py
. I hope I'm holding this the right way :).Your environment
The text was updated successfully, but these errors were encountered: