-
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
PermissionError raised, yet uncaught #643
Comments
I've tried different "moves", only one works as expected: if one want to move a subdirectory of the one where permissions are insufficient (then the PermissionError is caught as expected). Otherwise: moving a file or a directory from "outside" to the 'forbidden' one, or renaming a file inside it, leads to the same errors as described in the first post. On another hand, using Here is a commented version of the second test, extended:
|
I will have a closer look later, but have you checked how the real file system behaves in these cases? |
Test number 04, using
|
Thank you, I guess in this case the permission error is raised inside the exception handler in another function, where pyfakefs raises |
No problem! I hope I haven't missed anything obvious. |
Ok, I think I found the problem: in the fake fs, renaming is done by removing the file from the old directory entry and adding it to the new one. If the latter fails due to a permission error, the file stays removed, e.g. it is effectively deleted. |
Happy if that leads to improve pyfakefs! And thank you for your work and quick answers, that's fantastic! I do not want to urge you, there's anyway no hurry for me to get it fixed quickly (I think I can work around the bug making the move myself in two steps, copying to dest and then removing the source, as |
- rename is implemented via remove/add, a failed add shall revert the remove - see pytest-dev#643
- rename is implemented via remove/add, a failed add shall revert the remove - see #643
…ed via remove/add, a failed add shall revert the remove - see #643
@nicolashainaux - please check if the master branch works for you now. |
Yes, it works! Thanks a lot!
|
Describe the bug
Trying to move a file to a directory without write permissions does raise a PermissionError (as expected) that cannot be caught (unexpected).
I'm puzzled about this, but cannot find out where I possibly could have wrongly written the tests, nor can I figure out how to get to catch the exception and why it does not get caught. I notice there's another exception raised "in the same time", that tells
FileNotFoundError: [Errno 2] No such file or directory in the fake filesystem: PosixPath('/rootpath/dir2/f1.txt')
, but this file has been created. I think it's maybe because it gets deleted at some point during themove()
call, though I do not understand why it is deleted before the copy has been done.How To Reproduce
Here are two tests failing exactly in the same way.
fs
is the regularpyfakefs
'sfs
fixture.The situation is the same in both tests, I only changed the test itself: in the first test I only directly try to catch the exception, in the second one, I use the
pytest
'sraises()
feature for that.Both times, the exception is raised, as stated in the logs, but it is not caught.
Output of
test_catch_permission_error01
:Output of
test_catch_permission_error02
:Your environment
The text was updated successfully, but these errors were encountered: