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

os.scandir do not raise OSError when target is not directory #498

Closed
Gapex opened this issue Oct 25, 2019 · 3 comments
Closed

os.scandir do not raise OSError when target is not directory #498

Gapex opened this issue Oct 25, 2019 · 3 comments
Labels

Comments

@Gapex
Copy link

Gapex commented Oct 25, 2019

Describe the bug
As stated in the doc of scandir in pyfakefs, https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/fake_scandir.py#L186, scandir raises OSError if target is not directory, but acutally not.

import os

from pyfakefs.fake_filesystem_unittest import Patcher

with Patcher() as patcher:
    print(os.listdir('.'))
    print(list(os.scandir('not_exist_dir')))

print(os.listdir('.'))
print(list(os.scandir('not_exist_dir')))

run the above code: python main2.py, output:

['tmp']
[]
['main2.py']
Traceback (most recent call last):
  File "main2.py", line 10, in <module>
    print(list(os.scandir('not_exist_dir')))
FileNotFoundError: [Errno 2] No such file or directory: 'not_exist_dir'

My enviroment

Linux-4.15.0-55.60-x86_64-with-debian-stretch-sid


Python 3.6.4 |Anaconda, Inc.| (default, Mar 13 2018, 01:15:57) 
[GCC 7.2.0]

output: pyfakefs 3.6.1
@mrbean-bremen
Copy link
Member

Thanks for the report!
What the comment tries to say, is that is raises if the path points to a regular file. The case of a non-existent path seems not to be handled...
I'm traveling right now and will be back in a week, I will have a look then.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Nov 1, 2019
@mrbean-bremen
Copy link
Member

@Gapex - shall be fixed in master, please check!

@Gapex
Copy link
Author

Gapex commented Nov 3, 2019

that's wonderful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants