diff --git a/Lib/test/support/import_helper.py b/Lib/test/support/import_helper.py index 43ae3148342..efa8ffad6a8 100644 --- a/Lib/test/support/import_helper.py +++ b/Lib/test/support/import_helper.py @@ -2,6 +2,7 @@ import importlib import importlib.util import os +import shutil import sys import unittest import warnings @@ -58,7 +59,7 @@ def make_legacy_pyc(source): pyc_file = importlib.util.cache_from_source(source) up_one = os.path.dirname(os.path.abspath(source)) legacy_pyc = os.path.join(up_one, source + 'c') - os.rename(pyc_file, legacy_pyc) + shutil.move(pyc_file, legacy_pyc) return legacy_pyc diff --git a/Misc/NEWS.d/next/Tests/2022-02-07-12-40-45.bpo-46678.zfOrgL.rst b/Misc/NEWS.d/next/Tests/2022-02-07-12-40-45.bpo-46678.zfOrgL.rst new file mode 100644 index 00000000000..e369cb1f67b --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-02-07-12-40-45.bpo-46678.zfOrgL.rst @@ -0,0 +1,3 @@ +The function ``make_legacy_pyc`` in ``Lib/test/support/import_helper.py`` no +longer fails when ``PYTHONPYCACHEPREFIX`` is set to a directory on a +different device from where tempfiles are stored.