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

Permission Denied Error for root owned folder #9089

Open
rbracco opened this issue Sep 13, 2021 · 1 comment
Open

Permission Denied Error for root owned folder #9089

rbracco opened this issue Sep 13, 2021 · 1 comment
Labels
topic: collection related to the collection phase type: bug problem that needs to be addressed

Comments

@rbracco
Copy link

rbracco commented Sep 13, 2021

Bug

I was adding tests as a user to a project that contains a symlinked subfolder owned by root (so I don't have access to it as my normal user). In the collections process pytest fails with a PermissionError: [Errno 13] Permission denied (stack trace below). sudo pytest works but I don't want to have to run my tests as root.

Attempted fixes

I have tried using a pytest.ini file that uses norecursedirs = privileged_dir or addopts --ignore=privileged_dir but it appears the issue occurs during collection when pytest tries to check if the directory is a file and that raises a PermissionError.

Possible Patch

I monkey-patched main.py to do the following and calling pytest is now working.

# main.py (line ~685)
for direntry in visit(str(argpath), self._recurse):
    try:
        if not direntry.is_file():
            continue
     except PermissionError:
         warnings.warn(f"PyTest could not check folder {direntry} due to PermissionError")
         continue

Stack Trace

../anaconda3/lib/python3.8/site-packages/_pytest/runner.py:310: in from_call
    result = func()  # type: Optional[TResult]
../anaconda3/lib/python3.8/site-packages/_pytest/runner.py:340: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../anaconda3/lib/python3.8/site-packages/_pytest/main.py:685: in collect
    if not direntry.is_file():
E   PermissionError: [Errno 13] Permission denied: '/home/project/privileged_dir'
@Zac-HD Zac-HD added topic: collection related to the collection phase type: bug problem that needs to be addressed labels Sep 15, 2021
@anushkrishnav
Copy link

Having a similar issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants