diff --git a/newsfragments/4403.bugfix.rst b/newsfragments/4403.bugfix.rst new file mode 100644 index 0000000000..c07cd48c7e --- /dev/null +++ b/newsfragments/4403.bugfix.rst @@ -0,0 +1 @@ +Replace use of mktemp with can_symlink from the stdlib test suite. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index aa7fa372b3..9b46f93bbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,6 +68,8 @@ testing = [ # workaround for pypa/setuptools#4333 "pyproject-hooks!=1.1", + + "jaraco.test", ] docs = [ # upstream diff --git a/setuptools/tests/compat/__init__.py b/setuptools/tests/compat/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setuptools/tests/compat/py39.py b/setuptools/tests/compat/py39.py new file mode 100644 index 0000000000..9c86065cd2 --- /dev/null +++ b/setuptools/tests/compat/py39.py @@ -0,0 +1,4 @@ +from jaraco.test.cpython import from_test_support, try_import + + +os_helper = try_import('os_helper') or from_test_support('can_symlink') diff --git a/setuptools/tests/test_find_packages.py b/setuptools/tests/test_find_packages.py index 4fefd3dccf..f32cc2f58e 100644 --- a/setuptools/tests/test_find_packages.py +++ b/setuptools/tests/test_find_packages.py @@ -10,20 +10,7 @@ from setuptools import find_namespace_packages from setuptools.discovery import FlatLayoutPackageFinder - -# modeled after CPython's test.support.can_symlink -def can_symlink(): - TESTFN = tempfile.mktemp() - symlink_path = TESTFN + "can_symlink" - try: - os.symlink(TESTFN, symlink_path) - can = True - except (OSError, NotImplementedError, AttributeError): - can = False - else: - os.remove(symlink_path) - globals().update(can_symlink=lambda: can) - return can +from .compat.py39 import os_helper class TestFindPackages: @@ -123,7 +110,7 @@ def test_dir_with_packages_in_subdir_is_excluded(self): packages = find_packages(self.dist_dir) assert 'build.pkg' not in packages - @pytest.mark.skipif(not can_symlink(), reason='Symlink support required') + @pytest.mark.skipif(not os_helper.can_symlink(), reason='Symlink support required') def test_symlinked_packages_are_included(self): """ A symbolically-linked directory should be treated like any other diff --git a/setuptools/tests/test_find_py_modules.py b/setuptools/tests/test_find_py_modules.py index c110f8f561..2459c98fa3 100644 --- a/setuptools/tests/test_find_py_modules.py +++ b/setuptools/tests/test_find_py_modules.py @@ -6,7 +6,8 @@ from setuptools.discovery import FlatLayoutModuleFinder, ModuleFinder -from .test_find_packages import can_symlink, ensure_files +from .test_find_packages import ensure_files +from .compat.py39 import os_helper class TestModuleFinder: @@ -39,7 +40,7 @@ def test_finder(self, tmp_path, example): ensure_files(tmp_path, files) assert self.find(tmp_path, **kwargs) == set(expected_modules) - @pytest.mark.skipif(not can_symlink(), reason='Symlink support required') + @pytest.mark.skipif(not os_helper.can_symlink(), reason='Symlink support required') def test_symlinked_packages_are_included(self, tmp_path): src = "_myfiles/file.py" ensure_files(tmp_path, [src])