Skip to content

Commit 6d39656

Browse files
committed
Replace use of mktemp with can_symlink from the stdlib test suite.
Closes pypa#4403
1 parent 7a68e60 commit 6d39656

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

newsfragments/4403.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace use of mktemp with can_symlink from the stdlib test suite.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ testing = [
6868

6969
# workaround for pypa/setuptools#4333
7070
"pyproject-hooks!=1.1",
71+
72+
"jaraco.test",
7173
]
7274
docs = [
7375
# upstream

setuptools/tests/compat/__init__.py

Whitespace-only changes.

setuptools/tests/compat/py39.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from jaraco.test.cpython import from_test_support, try_import
2+
3+
4+
os_helper = try_import('os_helper') or from_test_support('can_symlink')

setuptools/tests/test_find_packages.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,7 @@
1010
from setuptools import find_namespace_packages
1111
from setuptools.discovery import FlatLayoutPackageFinder
1212

13-
14-
# modeled after CPython's test.support.can_symlink
15-
def can_symlink():
16-
TESTFN = tempfile.mktemp()
17-
symlink_path = TESTFN + "can_symlink"
18-
try:
19-
os.symlink(TESTFN, symlink_path)
20-
can = True
21-
except (OSError, NotImplementedError, AttributeError):
22-
can = False
23-
else:
24-
os.remove(symlink_path)
25-
globals().update(can_symlink=lambda: can)
26-
return can
13+
from .compat.py39 import os_helper
2714

2815

2916
class TestFindPackages:
@@ -123,7 +110,7 @@ def test_dir_with_packages_in_subdir_is_excluded(self):
123110
packages = find_packages(self.dist_dir)
124111
assert 'build.pkg' not in packages
125112

126-
@pytest.mark.skipif(not can_symlink(), reason='Symlink support required')
113+
@pytest.mark.skipif(not os_helper.can_symlink(), reason='Symlink support required')
127114
def test_symlinked_packages_are_included(self):
128115
"""
129116
A symbolically-linked directory should be treated like any other

setuptools/tests/test_find_py_modules.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
from setuptools.discovery import FlatLayoutModuleFinder, ModuleFinder
88

9-
from .test_find_packages import can_symlink, ensure_files
9+
from .test_find_packages import ensure_files
10+
from .compat.py39 import os_helper
1011

1112

1213
class TestModuleFinder:
@@ -39,7 +40,7 @@ def test_finder(self, tmp_path, example):
3940
ensure_files(tmp_path, files)
4041
assert self.find(tmp_path, **kwargs) == set(expected_modules)
4142

42-
@pytest.mark.skipif(not can_symlink(), reason='Symlink support required')
43+
@pytest.mark.skipif(not os_helper.can_symlink(), reason='Symlink support required')
4344
def test_symlinked_packages_are_included(self, tmp_path):
4445
src = "_myfiles/file.py"
4546
ensure_files(tmp_path, [src])

0 commit comments

Comments
 (0)