-
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
add_real_directory
does not work after chdir
#355
Comments
Thanks for the report - I will have a look! |
So, to understand this: this is inside a unit test, or after setting up Patcher? E.g. |
I'm trying to reproduce this, but until now it works correctly for me - so I'm obviously doing something different. I need a bit more context to be able to reproduce this... |
Yes, this is inside a unit test/after patcher is set up ( |
This code import os
def test_something(fs):
fs.create_dir("/Users/acervin/somethingfake")
os.chdir("/Users/acervin/somethingfake")
fs.add_real_directory("/Users/acervin/test")
print(os.listdir("/Users/acervin/test"))
print(os.listdir("/Users/acervin/somethingfake/Users/acervin/test"))
assert os.listdir("/Users/acervin/test") gives this output and the folder |
And if I remove the call to |
Ok, thanks! I will have another look in the evening. |
Unfortunately I couldn't reproduce this under Windows, so I think it is Unix-specific. My Ubuntu got trashed with the latest Windows 10 reinstall, and I couldn't get the grub menu to show up even after an Ubuntu reinstall, grub-update and the like, so I'm giving up for today. Got to love Windows 10... |
Yeah, it is specific to *NIX and I think it caused by the code here: https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/fake_filesystem.py#L394. When it is normalizing it ignores the leading slash (that denotes the root) since it says elif not self._starts_with_root_path(path):
# Prefix relative paths with cwd, if cwd is not root.
... |
Thanks - that helped! So the real bug is in |
I could reproduce the problem under Linux (got it running again) before the fix, it is gone now - closing. |
Awesome thanks! |
If I do an
os.chdir()
call before callingadd_real_directory
with an absolute path,os.listdir()
on that directory returns nothing since target path is set to the combination of the current directory and the specified path toadd_real_directory
.Example
the call to
os.listdir()
returns nothing in this case since the file gets added as/Users/abbe/test/Users/abbe/real
instead of/Users/abbe/real
.The text was updated successfully, but these errors were encountered: