gh-116303: Skip test module dependent tests if test modules are unavailable (#117341)

This commit is contained in:
Erlend E. Aasland 2024-04-03 15:11:36 +02:00 committed by GitHub
parent 2ec6bb4111
commit ea94b3b149
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 255 additions and 123 deletions

View file

@ -19,6 +19,13 @@ import textwrap
if not support.has_subprocess_support:
raise unittest.SkipTest("test module requires subprocess")
try:
import _testinternalcapi
except ImportError:
_testinternalcapi = None
MACOS = (sys.platform == 'darwin')
PYMEM_ALLOCATOR_NOT_SET = 0
PYMEM_ALLOCATOR_DEBUG = 2
@ -352,6 +359,7 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase):
self.assertEqual(out, 'Finalized\n' * INIT_LOOPS)
@support.requires_specialization
@unittest.skipUnless(support.TEST_MODULES_ENABLED, "requires test modules")
def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
# https://github.com/python/cpython/issues/92031
@ -396,6 +404,8 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase):
out, err = self.run_embedded_interpreter("test_repeated_init_exec", code)
self.assertEqual(out, '9\n' * INIT_LOOPS)
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
maxDiff = 4096
UTF8_MODE_ERRORS = ('surrogatepass' if MS_WINDOWS else 'surrogateescape')
@ -1588,7 +1598,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
# The global path configuration (_Py_path_config) must be a copy
# of the path configuration of PyInterpreter.config (PyConfig).
ctypes = import_helper.import_module('ctypes')
_testinternalcapi = import_helper.import_module('_testinternalcapi')
def get_func(name):
func = getattr(ctypes.pythonapi, name)
@ -1784,6 +1793,7 @@ class MiscTests(EmbeddingTestsMixin, unittest.TestCase):
# See bpo-44133
@unittest.skipIf(os.name == 'nt',
'Py_FrozenMain is not exported on Windows')
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
def test_frozenmain(self):
env = dict(os.environ)
env['PYTHONUNBUFFERED'] = '1'