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

shutil.rmtree failing in OSType.WINDOWS with PermissionError #979

Closed
gsnedders opened this issue Mar 14, 2024 · 2 comments · Fixed by #980
Closed

shutil.rmtree failing in OSType.WINDOWS with PermissionError #979

gsnedders opened this issue Mar 14, 2024 · 2 comments · Fixed by #980
Labels

Comments

@gsnedders
Copy link

Describe the bug

I expect this to succeed, and not fail.

Traceback (most recent call last):
  File "/private/var/folders/qk/hmjj9_lx2cg3_4v3vx3y7y_w0000gn/T/tmp.L4ZwvgaUdy/test.py", line 12, in <module>
    shutil.rmtree("C:\\test.checkout\\LayoutTests\\imported\\w3c")
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/shutil.py", line 781, in rmtree
    onexc(os.open, path, err)
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/shutil.py", line 778, in rmtree
    fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/qk/hmjj9_lx2cg3_4v3vx3y7y_w0000gn/T/tmp.L4ZwvgaUdy/venv/lib/python3.12/site-packages/pyfakefs/fake_os.py", line 1353, in wrapped
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/qk/hmjj9_lx2cg3_4v3vx3y7y_w0000gn/T/tmp.L4ZwvgaUdy/venv/lib/python3.12/site-packages/pyfakefs/fake_os.py", line 290, in open
    fake_file = FakeFileOpen(
                ^^^^^^^^^^^^^
  File "/private/var/folders/qk/hmjj9_lx2cg3_4v3vx3y7y_w0000gn/T/tmp.L4ZwvgaUdy/venv/lib/python3.12/site-packages/pyfakefs/fake_open.py", line 97, in __call__
    return self.call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/qk/hmjj9_lx2cg3_4v3vx3y7y_w0000gn/T/tmp.L4ZwvgaUdy/venv/lib/python3.12/site-packages/pyfakefs/fake_open.py", line 205, in call
    self.filesystem.raise_os_error(errno.EACCES, file_path)
  File "/private/var/folders/qk/hmjj9_lx2cg3_4v3vx3y7y_w0000gn/T/tmp.L4ZwvgaUdy/venv/lib/python3.12/site-packages/pyfakefs/fake_filesystem.py", line 427, in raise_os_error
    raise OSError(err_no, message, filename)
PermissionError: [Errno 13] Permission denied in the fake filesystem: 'C:\\test.checkout\\LayoutTests\\imported\\w3c'

How To Reproduce

import os
import shutil

from pyfakefs.fake_filesystem import OSType
from pyfakefs.fake_filesystem_unittest import Patcher

with Patcher() as patcher:
    fs = patcher.fs
    fs.os = OSType.WINDOWS

    os.makedirs("C:\\test.checkout\\LayoutTests\\imported\\w3c\\resources")
    shutil.rmtree("C:\\test.checkout\\LayoutTests\\imported\\w3c")

Your environment

% python -c "import platform; print(platform.platform())"
python -c "import sys; print('Python', sys.version)"
python -c "from pyfakefs import __version__; print('pyfakefs', __version__)"
python -c "import pytest; print('pytest', pytest.__version__)"
macOS-14.4-arm64-arm-64bit
Python 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
pyfakefs 5.3.5
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pytest'
@mrbean-bremen
Copy link
Member

Thanks for the report!

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Mar 14, 2024
- the fd functions that are used for rmtree are not available under Windows
-> switched of the usage of these function in the fake fs
- fixes pytest-dev#979
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Mar 14, 2024
- the fd functions that are used for rmtree are not available under Windows
-> switched of the usage of these function in the fake fs
- fixes pytest-dev#979
mrbean-bremen added a commit that referenced this issue Mar 14, 2024
- the fd functions that are used for rmtree are not available under Windows
-> switched of the usage of these function in the fake fs
- fixes #979
@mrbean-bremen
Copy link
Member

Should be fixed in main now, please check!

It may still be some time until the next release, as there are a few issues I want to handle before that.

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