Skip to content

Commit ca0cc9c

Browse files
authored
gh-92820: Skip test_cppext if _ctypes is missing (#92844)
Add @test.support.requires_venv_with_pip decorator.
1 parent a487623 commit ca0cc9c

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Lib/test/support/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,3 +2183,20 @@ def clear_ignored_deprecations(*tokens: object) -> None:
21832183
if warnings.filters != new_filters:
21842184
warnings.filters[:] = new_filters
21852185
warnings._filters_mutated()
2186+
2187+
2188+
# Skip a test if venv with pip is known to not work.
2189+
def requires_venv_with_pip():
2190+
# ensurepip requires zlib to open ZIP archives (.whl binary wheel packages)
2191+
try:
2192+
import zlib
2193+
except ImportError:
2194+
return unittest.skipIf(True, "venv: ensurepip requires zlib")
2195+
2196+
# bpo-26610: pip/pep425tags.py requires ctypes.
2197+
# gh-92820: setuptools/windows_support.py uses ctypes (setuptools 58.1).
2198+
try:
2199+
import ctypes
2200+
except ImportError:
2201+
ctypes = None
2202+
return unittest.skipUnless(ctypes, 'venv: pip requires ctypes')

Lib/test/test_cppext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class TestCPPExt(unittest.TestCase):
1919
# With MSVC, the linker fails with: cannot open file 'python311.lib'
2020
# https://github.com/python/cpython/pull/32175#issuecomment-1111175897
2121
@unittest.skipIf(MS_WINDOWS, 'test fails on Windows')
22+
# the test uses venv+pip: skip if it's not available
23+
@support.requires_venv_with_pip()
2224
def test_build(self):
2325
# Build in a temporary directory
2426
with os_helper.temp_cwd():

Lib/test/test_venv.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import tempfile
1717
from test.support import (captured_stdout, captured_stderr, requires_zlib,
1818
skip_if_broken_multiprocessing_synchronize, verbose,
19-
requires_subprocess, is_emscripten)
19+
requires_subprocess, is_emscripten,
20+
requires_venv_with_pip)
2021
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
2122
import unittest
2223
import venv
@@ -605,9 +606,7 @@ def do_test_with_pip(self, system_site_packages):
605606
if not system_site_packages:
606607
self.assert_pip_not_installed()
607608

608-
# Issue #26610: pip/pep425tags.py requires ctypes
609-
@unittest.skipUnless(ctypes, 'pip requires ctypes')
610-
@requires_zlib()
609+
@requires_venv_with_pip()
611610
def test_with_pip(self):
612611
self.do_test_with_pip(False)
613612
self.do_test_with_pip(True)

0 commit comments

Comments
 (0)