Skip to content

Unable to use pytest from mapped network drive #5826

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

Closed
4 tasks done
abhilash1in opened this issue Sep 7, 2019 · 11 comments
Closed
4 tasks done

Unable to use pytest from mapped network drive #5826

abhilash1in opened this issue Sep 7, 2019 · 11 comments
Labels
platform: windows windows platform-specific problem type: bug problem that needs to be addressed

Comments

@abhilash1in
Copy link

abhilash1in commented Sep 7, 2019

  • a detailed description of the bug or suggestion
    Running pyest --version using PowerShell displays the pytest version when I'm in my home directory or any other local directory on my Windows machine. When I cd into a mapped network drive (Q:\) and run pyest --version, I get PermissionError: [WinError 5] Access is denied: '.'. I get the same error when I run pyest --version inside as well as outside a virtual environment when I'm in a mapped network drive.
  • output of pip list from the virtual environment you are using
(env) PS Q:\Projects\Abhilash\Feeds> pip list
Package            Version
------------------ -------
asn1crypto         0.24.0
astroid            2.2.5
atomicwrites       1.3.0
attrs              19.1.0
bcrypt             3.1.7
cffi               1.12.3
colorama           0.4.1
coverage           4.5.4
cryptography       2.7
importlib-metadata 0.20
isort              4.3.21
lazy-object-proxy  1.4.2
mccabe             0.6.1
more-itertools     7.2.0
packaging          19.1
paramiko           2.6.0
pip                19.0.3
pluggy             0.12.0
py                 1.8.0
pycparser          2.19
pylint             2.3.1
pymssql            2.1.4
PyNaCl             1.3.0
pyparsing          2.4.2
pytest             5.1.2
pytest-cov         2.7.1
setuptools         40.8.0
six                1.12.0
typed-ast          1.4.0
wcwidth            0.1.7
wrapt              1.11.2
zipp               0.6.0
You are using pip version 19.0.3, however version 19.2.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip'
command.
  • pytest and operating system versions
PS C:\Users\kishorea> pytest --version
This is pytest version 5.1.2, imported from c:\users\kishorea\appdata\local\programs\python\python37\lib\site-packages\pytest.py
setuptools registered plugins:
  pytest-cov-2.7.1 at c:\users\kishorea\appdata\local\programs\python\python37\lib\site-packages\pytest_cov\plugin.py
PS C:\Users\kishorea>
PS C:\Users\kishorea> (Get-WMIObject win32_operatingsystem).name
Microsoft Windows 10 Enterprise|C:\WINDOWS|\Device\Harddisk0\Partition4
  • minimal example if possible
PS C:\Users\kishorea> pytest --version
This is pytest version 5.1.2, imported from c:\users\kishorea\appdata\local\programs\python\python37\lib\site-packages\pytest.py
setuptools registered plugins:
  pytest-cov-2.7.1 at c:\users\kishorea\appdata\local\programs\python\python37\lib\site-packages\pytest_cov\plugin.py
PS C:\Users\kishorea> q:
PS Q:\> pytest --version
Traceback (most recent call last):
  File "c:\users\kishorea\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\kishorea\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\kishorea\AppData\Local\Programs\Python\Python37\Scripts\pytest.exe\__main__.py", line 9, in <module>
  File "c:\users\kishorea\appdata\local\programs\python\python37\lib\site-packages\_pytest\config\__init__.py", line 59, in main
    config = _prepareconfig(args, plugins)
  File "c:\users\kishorea\appdata\local\programs\python\python37\lib\site-packages\_pytest\config\__init__.py", line 195, in _prepareconfig
    config = get_config(args, plugins)
  File "c:\users\kishorea\appdata\local\programs\python\python37\lib\site-packages\_pytest\config\__init__.py", line 160, in get_config
    args=args, plugins=plugins, dir=Path().resolve()
  File "c:\users\kishorea\appdata\local\programs\python\python37\lib\pathlib.py", line 1151, in resolve
    s = self._flavour.resolve(self, strict=strict)
  File "c:\users\kishorea\appdata\local\programs\python\python37\lib\pathlib.py", line 202, in resolve
    s = self._ext_to_normal(_getfinalpathname(s))
PermissionError: [WinError 5] Access is denied: '.'
PS Q:\>
@blueyed blueyed added type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously platform: windows windows platform-specific problem and removed type: regression indicates a problem that was introduced in a release which was working previously labels Sep 7, 2019
@blueyed
Copy link
Contributor

blueyed commented Sep 7, 2019

Is this a regression? (i.e. did it work in older versions? (which?))
If so, can you git-bisect it?

@abhilash1in
Copy link
Author

I've not used pytest before, so I'm not sure if this is a regression.

@RonnyPfannschmidt
Copy link
Member

at first glance this looks like a windows issue of python, as it happens in the resolve method of pathlib

@dr-1
Copy link

dr-1 commented Sep 10, 2019

I get the same issue and for me it worked in previous versions. I git-bisected it and it appears that 6a9bf28 is the first bad commit.

Edit: Sorry, wrong reference. Updated.

@dr-1
Copy link

dr-1 commented Sep 10, 2019

Also, agreed that the issue comes from Python on Windows, as pathlib.Path().resolve() does not seem to be able to handle network drives. After a bit of research I'm not sure how to solve that, other than using the os module instead to get the current directory.

@adamkerz
Copy link

adamkerz commented Oct 2, 2019

Another issue related to Path().resolve() - #5905
Can Path().absolute() be used instead?

@Thibuko
Copy link

Thibuko commented Jan 10, 2020

Also, agreed that the issue comes from Python on Windows, as pathlib.Path().resolve() does not seem to be able to handle network drives. After a bit of research I'm not sure how to solve that, other than using the os module instead to get the current directory.

Seems that Python will not change anything and pytest should do the work: https://bugs.python.org/issue37993 resolution: not a bug

@RonnyPfannschmidt
Copy link
Member

@abhilash1in can you (or another windows user) verify if the issue disappears if Path().resolve() is repalced by Path.cwd() or Path.cwd().resolve()

@RonnyPfannschmidt
Copy link
Member

@Thibuko it seems that the issue that pops up in the python bug also means that pytest has to replace py.path.local.pyimport with a pathlib one as its no longer functional on windows

thanks for bringing the python issue to attention

@manum45
Copy link

manum45 commented Jul 23, 2020

A similar issue occurs on RAM disks (O:\ in this case):

O:\>C:\ProgramData\Anaconda3\python.exe -m pytest --version
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pytest.py", line 101, in <module>
    raise SystemExit(pytest.main())
  File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 71, in main
    config = _prepareconfig(args, plugins)
  File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 207, in _prepareconfig
    config = get_config(args, plugins)
  File "C:\ProgramData\Anaconda3\lib\site-packages\_pytest\config\__init__.py", line 172, in get_config
    args=args, plugins=plugins, dir=Path().resolve()
  File "C:\ProgramData\Anaconda3\lib\pathlib.py", line 1151, in resolve
    s = self._flavour.resolve(self, strict=strict)
  File "C:\ProgramData\Anaconda3\lib\pathlib.py", line 202, in resolve
    s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 1] Incorrect function: '.'

This behavior seems to be described here: https://bugs.python.org/issue31842

Edit:
Error occurs with:

Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

pytest                             5.2.1
pytest-arraydiff                   0.3
pytest-astropy                     0.5.0
pytest-doctestplus                 0.4.0
pytest-openfiles                   0.4.0
pytest-remotedata                  0.3.2
python-dateutil                    2.8.0

@nicoddemus
Copy link
Member

This will be fixed in pytest 6.0 because we are no longer resolving paths. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: windows windows platform-specific problem type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

8 participants