'PermissionError: [WinError 5] Access is denied pytest after conda install
PermissionError: [WinError 5] Access is denied - running pytest after fresh conda install
Environment
# packages in environment at C:\Users\rick\miniconda3\envs\xml:
#
# Name Version Build Channel
pytest 6.2.2 py39haa95532_2
(xml) c:\Users\rick>conda info
active environment : xml
active env location : C:\Users\rick\miniconda3\envs\xml
shell level : 2
user config file : C:\Users\rick\.condarc
populated config files : C:\Users\rick\.condarc
conda version : 4.9.2
conda-build version : not installed
python version : 3.9.2.final.0
virtual packages : __win=0=0
__archspec=1=x86_64
base environment : C:\Users\rick\miniconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\rick\miniconda3\pkgs
C:\Users\rick\.conda\pkgs
C:\Users\rick\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\rick\miniconda3\envs
C:\Users\rick\.conda\envs
C:\Users\rick\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.9.2 requests/2.25.1 CPython/3.9.2 Windows/10 Windows/10.0.18362
administrator : False
netrc file : None
offline mode : False
(xml) c:\Users\rick>pytest
=================================================== test session starts ===================================================
platform win32 -- Python 3.9.2, pytest-6.2.2, py-1.9.0, pluggy-0.13.1
rootdir: c:\Users\rick
collected 0 items / 1 error
========================================================= ERRORS ==========================================================
______________________________________________ ERROR collecting test session ______________________________________________
miniconda3\envs\xml\lib\site-packages\_pytest\runner.py:311: in from_call
result: Optional[TResult] = func()
miniconda3\envs\xml\lib\site-packages\_pytest\runner.py:341: in <lambda>
call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
miniconda3\envs\xml\lib\site-packages\_pytest\main.py:690: in collect
for direntry in visit(str(argpath), self._recurse):
miniconda3\envs\xml\lib\site-packages\_pytest\pathlib.py:613: in visit
yield from visit(entry.path, recurse)
miniconda3\envs\xml\lib\site-packages\_pytest\pathlib.py:613: in visit
yield from visit(entry.path, recurse)
miniconda3\envs\xml\lib\site-packages\_pytest\pathlib.py:613: in visit
yield from visit(entry.path, recurse)
miniconda3\envs\xml\lib\site-packages\_pytest\pathlib.py:598: in visit
for entry in os.scandir(path):
E PermissionError: [WinError 5] Access is denied: 'c:\\Users\\rick\\AppData\\Local\\Application Data'
================================================= short test summary info =================================================
ERROR - PermissionError: [WinError 5] Access is denied: 'c:\\Users\\rick\\AppData\\Local\\Application Data'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==================================================== 1 error in 2.35s =====================================================
From a Microsoft Technet post
The Application Data folder in that location is not a normal folder. It is a folder Junction and is normally hidden, by default. The only reason that the junction exists is to redirect legacy applications, that are hard coded to look for that folder, to the new location in Windows 7.
Seems odd that pytest would point to a deprecated "folder junction"? How to resolve?
Solution 1:[1]
Just run "pytest" from the directory you installed it or add it to the environmental variables. In your example: >cd miniconda3\envs\xml\lib\site-packages_pytest
Solution 2:[2]
pytest first tries to 'collect' tests - i.e. scans actual folder and its subfolders for python test files containing tests methods.
Looks like you've just installed (conda and) pytest and wanted to just try it, while being located at your os \users\rick folder, containing additional hidden\protected os folders which pytest lack permissions to access. I don't think pytest is deliberately trying to use this deprecated 'folder junction' ,it just happened to sit around your actual working folder at the moment. Running tests for real, you would know where to collect them, i.e. what folder to execute pytest from. For verify install only, run pytest from folder not containing any special os folders.
Collecting tests is also called 'test discovery' and can be parametrized and or configured, pytest docs touching the topic is here https://docs.pytest.org/en/7.0.x/explanation/goodpractices.html#test-discovery
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joe |
| Solution 2 |
