Skip to content

Commit

Permalink
Merge pull request pypa#4404 from pypa/bugfix/4403-no-mktemp
Browse files Browse the repository at this point in the history
Replace use of mktemp with can_symlink from the stdlib test suite.
  • Loading branch information
jaraco authored May 31, 2024
2 parents 33afc11 + 6d39656 commit f91fa3d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions newsfragments/4403.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace use of mktemp with can_symlink from the stdlib test suite.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ testing = [

# workaround for pypa/setuptools#4333
"pyproject-hooks!=1.1",

"jaraco.test",
]
docs = [
# upstream
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions setuptools/tests/compat/py39.py
Original file line number Diff line number Diff line change
@@ -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')
17 changes: 2 additions & 15 deletions setuptools/tests/test_find_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions setuptools/tests/test_find_py_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit f91fa3d

Please sign in to comment.