Skip to content

Commit 36b7e6c

Browse files
committed
Remove _testcapi.check_pyimport_addmodule()
Tests already covered by newly added tests.
1 parent 1d8342b commit 36b7e6c

File tree

2 files changed

+0
-71
lines changed

2 files changed

+0
-71
lines changed

Lib/test/test_import/__init__.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,30 +3311,6 @@ def test_basic_multiple_interpreters_reset_each(self):
33113311
# * module's global state was initialized, not reset
33123312

33133313

3314-
@cpython_only
3315-
class CAPITests(unittest.TestCase):
3316-
def test_pyimport_addmodule(self):
3317-
# gh-105922: Test PyImport_AddModuleRef(), PyImport_AddModule()
3318-
# and PyImport_AddModuleObject()
3319-
_testcapi = import_module("_testcapi")
3320-
for name in (
3321-
'sys', # frozen module
3322-
'test', # package
3323-
__name__, # package.module
3324-
):
3325-
_testcapi.check_pyimport_addmodule(name)
3326-
3327-
def test_pyimport_addmodule_create(self):
3328-
# gh-105922: Test PyImport_AddModuleRef(), create a new module
3329-
_testcapi = import_module("_testcapi")
3330-
name = 'dontexist'
3331-
self.assertNotIn(name, sys.modules)
3332-
self.addCleanup(unload, name)
3333-
3334-
mod = _testcapi.check_pyimport_addmodule(name)
3335-
self.assertIs(mod, sys.modules[name])
3336-
3337-
33383314
@cpython_only
33393315
class TestMagicNumber(unittest.TestCase):
33403316
def test_magic_number_endianness(self):

Modules/_testcapimodule.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,52 +3059,6 @@ function_set_closure(PyObject *self, PyObject *args)
30593059
Py_RETURN_NONE;
30603060
}
30613061

3062-
static PyObject *
3063-
check_pyimport_addmodule(PyObject *self, PyObject *args)
3064-
{
3065-
const char *name;
3066-
if (!PyArg_ParseTuple(args, "s", &name)) {
3067-
return NULL;
3068-
}
3069-
3070-
// test PyImport_AddModuleRef()
3071-
PyObject *module = PyImport_AddModuleRef(name);
3072-
if (module == NULL) {
3073-
return NULL;
3074-
}
3075-
assert(PyModule_Check(module));
3076-
// module is a strong reference
3077-
3078-
// test PyImport_AddModule()
3079-
PyObject *module2 = PyImport_AddModule(name);
3080-
if (module2 == NULL) {
3081-
goto error;
3082-
}
3083-
assert(PyModule_Check(module2));
3084-
assert(module2 == module);
3085-
// module2 is a borrowed ref
3086-
3087-
// test PyImport_AddModuleObject()
3088-
PyObject *name_obj = PyUnicode_FromString(name);
3089-
if (name_obj == NULL) {
3090-
goto error;
3091-
}
3092-
PyObject *module3 = PyImport_AddModuleObject(name_obj);
3093-
Py_DECREF(name_obj);
3094-
if (module3 == NULL) {
3095-
goto error;
3096-
}
3097-
assert(PyModule_Check(module3));
3098-
assert(module3 == module);
3099-
// module3 is a borrowed ref
3100-
3101-
return module;
3102-
3103-
error:
3104-
Py_DECREF(module);
3105-
return NULL;
3106-
}
3107-
31083062

31093063
static PyObject *
31103064
test_weakref_capi(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
@@ -3570,7 +3524,6 @@ static PyMethodDef TestMethods[] = {
35703524
{"function_set_kw_defaults", function_set_kw_defaults, METH_VARARGS, NULL},
35713525
{"function_get_closure", function_get_closure, METH_O, NULL},
35723526
{"function_set_closure", function_set_closure, METH_VARARGS, NULL},
3573-
{"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS},
35743527
{"test_weakref_capi", test_weakref_capi, METH_NOARGS},
35753528
{"function_set_warning", function_set_warning, METH_NOARGS},
35763529
{"test_critical_sections", test_critical_sections, METH_NOARGS},

0 commit comments

Comments
 (0)