diff --git a/tests/ptvsd/server/test_path_mapping.py b/tests/ptvsd/server/test_path_mapping.py index b6fd4873..970fb0af 100644 --- a/tests/ptvsd/server/test_path_mapping.py +++ b/tests/ptvsd/server/test_path_mapping.py @@ -15,7 +15,7 @@ from tests.patterns import some @pytest.mark.skipif(sys.platform == "win32", reason="Linux/Mac only test.") @pytest.mark.parametrize("os_type", ["INVALID", ""]) def test_client_ide_from_path_mapping_linux_backend( - pyfile, tmpdir, start_method, run_as, os_type + pyfile, start_method, run_as, os_type ): """ Test simulating that the backend is on Linux and the client is on Windows @@ -65,7 +65,7 @@ def test_client_ide_from_path_mapping_linux_backend( session.wait_for_exit() -def test_with_dot_remote_root(pyfile, tmpdir, start_method, run_as): +def test_with_dot_remote_root(pyfile, long_tmpdir, start_method, run_as): @pyfile def code_to_debug(): from debug_me import backchannel @@ -74,8 +74,8 @@ def test_with_dot_remote_root(pyfile, tmpdir, start_method, run_as): backchannel.send(os.path.abspath(__file__)) print("done") # @bp - path_local = tmpdir.mkdir("local") / "code_to_debug.py" - path_remote = tmpdir.mkdir("remote") / "code_to_debug.py" + path_local = long_tmpdir.mkdir("local") / "code_to_debug.py" + path_remote = long_tmpdir.mkdir("remote") / "code_to_debug.py" dir_local = path_local.dirname dir_remote = path_remote.dirname @@ -110,7 +110,7 @@ def test_with_dot_remote_root(pyfile, tmpdir, start_method, run_as): session.wait_for_exit() -def test_with_path_mappings(pyfile, tmpdir, start_method, run_as): +def test_with_path_mappings(pyfile, long_tmpdir, start_method, run_as): @pyfile def code_to_debug(): from debug_me import backchannel @@ -129,8 +129,8 @@ def test_with_path_mappings(pyfile, tmpdir, start_method, run_as): call_me_back.call_me_back(call_func) # @call_me_back print("done") - dir_local = tmpdir.mkdir("local") - dir_remote = tmpdir.mkdir("remote") + dir_local = long_tmpdir.mkdir("local") + dir_remote = long_tmpdir.mkdir("remote") path_local = dir_local / "code_to_debug.py" path_remote = dir_remote / "code_to_debug.py" diff --git a/tests/pytest_fixtures.py b/tests/pytest_fixtures.py index 9b56ef44..2c02165c 100644 --- a/tests/pytest_fixtures.py +++ b/tests/pytest_fixtures.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, unicode_literals import inspect import os import platform +import py.path import pytest import tempfile import threading @@ -97,8 +98,30 @@ def daemon(request): assert not thread.is_alive() +if platform.system() != 'Windows': + @pytest.fixture + def long_tmpdir(request, tmpdir): + return tmpdir +else: + import ctypes + + GetLongPathNameW = ctypes.windll.kernel32.GetLongPathNameW + GetLongPathNameW.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32] + GetLongPathNameW.restype = ctypes.c_uint32 + + @pytest.fixture + def long_tmpdir(request, tmpdir): + """Like tmpdir, but ensures that it's a long rather than short filename on Win32. + """ + path = compat.filename(tmpdir.strpath) + buffer = ctypes.create_unicode_buffer(512) + if GetLongPathNameW(path, buffer, len(buffer)): + path = buffer.value + return py.path.local(path) + + @pytest.fixture -def pyfile(request, tmpdir): +def pyfile(request, long_tmpdir): """A fixture providing a factory function that generates .py files. The returned factory takes a single function with an empty argument list, @@ -160,7 +183,7 @@ def pyfile(request, tmpdir): source = ''.join(source) # Write it to file. - tmpfile = tmpdir / (name + '.py') + tmpfile = long_tmpdir / (name + '.py') tmpfile.strpath = compat.filename(tmpfile.strpath) assert not tmpfile.check() tmpfile.write(source)