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

Call os.makedirs('', exist_ok=True) will not raise FileNotFoundError in fakefs #510

Closed
vuryleo opened this issue Jan 13, 2020 · 4 comments · Fixed by CyberGRX/twin-sister#3
Labels

Comments

@vuryleo
Copy link

vuryleo commented Jan 13, 2020

Describe the bug
os.makedirs('', exist_ok=True) will not raise FileNotFoundError

How To Reproduce

import os

from pyfakefs.fake_filesystem_unittest import Patcher

with Patcher():
    print('fakefs')
    os.makedirs('', exist_ok=True)

print('os')
os.makedirs('', exist_ok=True)

Output:

fakefs
os
Traceback (most recent call last):
  File "[redacted].py", line 10, in <module>
    os.makedirs('', exist_ok=True)
  File "/usr/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''

Your enviroment
Please run the following and paste the output.

Linux-4.15.0-55.60-x86_64-with-Ubuntu-18.04-bionic
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0]
pyfakefs 3.7.1
@mrbean-bremen
Copy link
Member

Ok, thanks - strange use case, I didn't know that it behaves that way. Will have a look tonight...

@vuryleo
Copy link
Author

vuryleo commented Jan 13, 2020

The use case is that we wanna implement something like shutil.move. So we need to makedirs(dirname(dst), exist_ok=True) first.

Then we encountered that dirname('local_file') == ''. Boom.

At last we wish to add this case to our unit test, and discovered that pyfakefs does not complain about this.

@mrbean-bremen
Copy link
Member

Ok, thanks - I still find the behavior a bit unexpected, and it seems not to be documented. Anyway, I will have a look later.

@mrbean-bremen
Copy link
Member

Turned out mkdir has the same behavior, and that was already implemented - so not so unexpected in the end, I guess...

mrbean-bremen added a commit that referenced this issue Mar 2, 2020
- fixes #510
- back-ported from master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants