diff --git a/news/7577.trivial b/news/7577.trivial new file mode 100644 index 000000000..e69de29bb diff --git a/tests/conftest.py b/tests/conftest.py index 16b5c6202..fd8204713 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -83,7 +83,13 @@ def tmpdir_factory(request, tmpdir_factory): """ yield tmpdir_factory if not request.config.getoption("--keep-tmpdir"): - tmpdir_factory.getbasetemp().remove(ignore_errors=True) + # py.path.remove() uses str paths on Python 2 and cannot + # handle non-ASCII file names. This works around the problem by + # passing a unicode object to rmtree(). + shutil.rmtree( + six.text_type(tmpdir_factory.getbasetemp()), + ignore_errors=True, + ) @pytest.fixture @@ -103,6 +109,9 @@ def tmpdir(request, tmpdir): # This should prevent us from needing a multiple gigabyte temporary # directory while running the tests. if not request.config.getoption("--keep-tmpdir"): + # py.path.remove() uses str paths on Python 2 and cannot + # handle non-ASCII file names. This works around the problem by + # passing a unicode object to rmtree(). shutil.rmtree(six.text_type(tmpdir), ignore_errors=True) diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index 10c9e47d6..9a55c156e 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -15,7 +15,7 @@ from textwrap import dedent from zipfile import ZipFile import pytest -from pip._vendor.six import PY2, ensure_binary +from pip._vendor.six import PY2, ensure_binary, text_type from scripttest import FoundDir, TestFileEnvironment from pip._internal.index.collector import LinkCollector @@ -1052,8 +1052,16 @@ def create_basic_wheel_for_package( path.parent.mkdir(exist_ok=True, parents=True) path.write_bytes(ensure_binary(files[fname])) + # The base_dir cast is required to make `shutil.make_archive()` use + # Unicode paths on Python 2, making it able to properly archive + # files with non-ASCII names. retval = script.scratch_path / archive_name - generated = shutil.make_archive(retval, 'zip', script.temp_path) + generated = shutil.make_archive( + retval, + 'zip', + root_dir=script.temp_path, + base_dir=text_type(os.curdir), + ) shutil.move(generated, retval) shutil.rmtree(script.temp_path)