Pytest-django: Windows: OSError: [WinError 123] due to pathlib changes

Created on 29 Aug 2018  ·  12Comments  ·  Source: pytest-dev/pytest-django

My pytest.ini has the following content:

[pytest]
DJANGO_SETTINGS_MODULE = project.settings_pytest
addopts = --doctest-modules --cov=. --cov-report html:./coverage/python/html
norecursedirs = .git .venv .vscode node_modules

I believe the Unix-like path passed to --cov-report is causing the latest version of pytest-django to crash on Windows. (Because it's in an .ini file, I don't know of any platform-independent way to specify it).

Here's the traceback that displays when running pytest:

Traceback (most recent call last):
  File "C:\Program Files\Python37\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\Python37\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Atul\.virtualenvs\tenants2-Gxdtcl1v\Scripts\pytest.exe\__main__.py", line 9, in <module>
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\_pytest\config\__init__.py", line 55, in main
    config = _prepareconfig(args, plugins)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\_pytest\config\__init__.py", line 180, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\callers.py", line 196, in _multicall
    gen.send(outcome)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\_pytest\helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\_pytest\config\__init__.py", line 612, in pytest_cmdline_parse
    self.parse(args)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\_pytest\config\__init__.py", line 777, in parse
    self._preparse(args, addopts=addopts)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\_pytest\config\__init__.py", line 739, in _preparse
    early_config=self, args=args, parser=self._parser
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\callers.py", line 201, in _multicall
    return outcome.get_result()
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pluggy\callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pytest_django\plugin.py", line 209, in pytest_load_initial_conftests
    _django_project_scan_outcome = _add_django_project_to_path(args)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pytest_django\plugin.py", line 140, in _add_django_project_to_path
    project_dir = find_django_path(args)
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pytest_django\plugin.py", line 127, in find_django_path
    args = [p for p in args if p.is_dir()]
  File "c:\users\atul\.virtualenvs\tenants2-gxdtcl1v\lib\site-packages\pytest_django\plugin.py", line 127, in <listcomp>
    args = [p for p in args if p.is_dir()]
  File "C:\Program Files\Python37\Lib\pathlib.py", line 1330, in is_dir
    return S_ISDIR(self.stat().st_mode)
  File "C:\Program Files\Python37\Lib\pathlib.py", line 1140, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'html:.\\coverage\\python\\html'
bug

All 12 comments

Appears to be due to the switch to pathlib.

/cc @voidus

Try --cov-report=html:./coverage/python/html as a workaround.

Hi I also have the problem with pytest .\app\tests.py::WebServiceTest

Does the workaround work?

Hi
OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: 'app\tests.py::WebServiceTest'
(error text is german )

And this is my pytest.ini file. No coverage stuff.

[pytest]
DJANGO_SETTINGS_MODULE = DjangoBasisLager.settings
python_files = tests.py tests_*.py *_tests.py

The problem is with the path to the test file.

Full error log:
(DjangoBasisLager--RYvLsCA) PS C:UsersLubitzworkspacebasislagerDjangoBasisLager> pytest .\app\tests.py::WebServiceTest
Traceback (most recent call last):
File "C:Program FilesPython36Librunpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:Program FilesPython36Librunpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:UsersLubitz.virtualenvsDjangoBasisLager--RYvLsCAScriptspytest.exe__main__.py", line 9, in
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packages_pytestconfig__init__.py", line 56, in main
config = _prepareconfig(args, plugins)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packages_pytestconfig__init__.py", line 181, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggyhooks.py", line 258, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggymanager.py", line 67, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggymanager.py", line 61, in
firstresult=hook.spec_opts.get('firstresult'),
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggycallers.py", line 196, in _multicall
gen.send(outcome)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packages_pytesthelpconfig.py", line 89, in pytest_cmdline_parse
config = outcome.get_result()
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggycallers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggycallers.py", line 180, in _multicall
res = hook_impl.function(args)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packages_pytestconfig__init__.py", line 617, in pytest_cmdline_parse
self.parse(args)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packages_pytestconfig__init__.py", line 782, in parse
self._preparse(args, addopts=addopts)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packages_pytestconfig__init__.py", line 744, in _preparse
early_config=self, args=args, parser=self._parser
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggyhooks.py", line 258, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggymanager.py", line 67, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggymanager.py", line 61, in
firstresult=hook.spec_opts.get('firstresult'),
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggycallers.py", line 201, in _multicall
return outcome.get_result()
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggycallers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File "c:userslubitz.virtualenvsdjangobasislager--ryvlscalibsite-packagespluggycallers.py", line 180, in _multicall
res = hook_impl.function(
args)
File "C:UsersLubitz.virtualenvsDjangoBasisLager--RYvLsCAlibsite-packagespytest_djangoplugin.py", line 209, in pytest_load_initial_conftests
_django_project_scan_outcome = _add_django_project_to_path(args)
File "C:UsersLubitz.virtualenvsDjangoBasisLager--RYvLsCAlibsite-packagespytest_djangoplugin.py", line 140, in _add_django_project_to_path
project_dir = find_django_path(args)
File "C:UsersLubitz.virtualenvsDjangoBasisLager--RYvLsCAlibsite-packagespytest_djangoplugin.py", line 127, in find_django_path
args = [p for p in args if p.is_dir()]
File "C:UsersLubitz.virtualenvsDjangoBasisLager--RYvLsCAlibsite-packagespytest_djangoplugin.py", line 127, in
args = [p for p in args if p.is_dir()]
File "C:Program FilesPython36Libpathlib.py", line 1346, in is_dir
return S_ISDIR(self.stat().st_mode)
File "C:Program FilesPython36Libpathlib.py", line 1156, in stat
return self._accessor.stat(self)
File "C:Program FilesPython36Libpathlib.py", line 387, in wrapped
return strfunc(str(pathobj), *args)
OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: 'app\tests.py::WebServiceTest'

Ah, I see.. it gets triggered for you for a normal arg.

@voidus
Can you look into fixing this, please?

Hi can I help in any way to fix the problem? Is there a brunch I can test or should I look into the Problem to fix it?

@pinguin999
Nothing to test.
It is related to the pathlib code being added (see your stacktrace).
Would be great if you could provide a PR with a fix.

@pinguin999 I'm not exactly sure what the cause of this error is, but I suspect that the test class specification (::WebServiceTest) might be it.

I created a branch where that part is split off before running the tests and it would be great if you could try it, as I don't have a windows machine with a dev setup available. You can find it in the oserror_pathlib branch in my fork at https://github.com/voidus/pytest-django.

https://github.com/voidus/pytest-django/tree/oserror_pathlib

Yes, apparently the ":" in the arg bails out on Windows.
I think your patch is fine, I've created https://github.com/pytest-dev/pytest-django/pull/648 with it.

Hi
sorry I was on holidays.
I updated to 3.4.3 and it's working.

Thank You

# remove this line of code ====== 'module_name',
from INSTALLED_APPS list

Well this happened to me as well.
Firstly make sure that youre starting app in the project folder
for eg:
"django-admin startproject website
cd website
django-admin startapp music"

Was this page helpful?
0 / 5 - 0 ratings