Path.cwd() different when used as default argument #853
Replies: 10 comments
|
Mhm... I thought I found my mistake. But using The output is the same. |
|
Thanks - this is indeed a shortcoming of the patching of default arguments. Apart from the fact that it is off by default (which you already found), it only checks the arguments for file system functions, not for file system classes (in this case The only way to prevent this currently is to reload the module in question using |
|
Thanks a lot. From my side you can close that Issue. Just for documentation to others here the code that works. I separated it into two files. Here is This is |
|
Thanks - I'll leave it open for a while to investigate if this can be fixed without the need to reload. |
|
I am sorry to bother you again. But maybe I created another edge case. The example code I used here worked with your solution. But porting that into my real productive code doesn't help. I assume this is because of the way I structure that package with it's sub-packages and how I import them. Again the problem is that the Please see the original repo The relevant parts of the tree looking like this The code to test is located in the file The function to test is The test is here You have to install the package in Developer Mode via I invoke the test via Would be glad if you could take a look into it. Maybe I just have to modify the |
|
Ok, I will probably have a look at it tomorrow. |
|
Ok, I had a look, and the reason why it does not work is a bit obscure: it's a problem of the reload order. As |
|
Bähm! Thats it! From a users perspective reading the documentation I would suggest to create a separate section with such edge cases. Maybe you can link to that edge cases in the regular documentation about |
|
Yes, that's a good idea. In my experience, most people don't read the documentation, but there are at least some for whom that may be helpful 😀. |
|
After thinking about this I realized that there is really no way to fix this without reloading the code. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm not new to PyFakeFS but this took me a while to find out the cause of my problem. But I am still not sure if this is a bug or just a misunderstanding on my site.
When PyFakeFS is activated the return value of
pathlib.Path.cwd()should be/.But when I use
pathlib.Path.cwd()as a default argument in a function it returns the working directory of the real file system.See this code to reproduce:
The output
But the output I would expect should be this
I'm using Python 3.9.2 on Debian 11 (stable) with
pyfakefs.__version__ == '4.6.3'.All reactions