You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'
The text was updated successfully, but these errors were encountered:
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
oraddopts --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.Stack Trace
The text was updated successfully, but these errors were encountered: