diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index 7269f5aee2e4afc..e81eb6f0a86fe86 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -294,6 +294,12 @@ def clean_up(): if lookedup is not _testsinglephase: raise Exception((_testsinglephase, lookedup)) + # Attrs set in the module init func are in m_copy. + _initialized = _testsinglephase._initialized + initialized = _testsinglephase.initialized() + if _initialized != initialized: + raise Exception((_initialized, initialized)) + # Attrs set after loading are not in m_copy. if hasattr(_testsinglephase, 'spam'): raise Exception(_testsinglephase.spam) diff --git a/Modules/_testsinglephase.c b/Modules/_testsinglephase.c index 8d72cc08451a1f0..565221c887e5aef 100644 --- a/Modules/_testsinglephase.c +++ b/Modules/_testsinglephase.c @@ -134,6 +134,16 @@ init_module(PyObject *module, module_state *state) if (PyModule_AddObjectRef(module, "str_const", state->str_const) != 0) { return -1; } + + double d = _PyTime_AsSecondsDouble(state->initialized); + PyObject *initialized = PyFloat_FromDouble(d); + if (initialized == NULL) { + return -1; + } + if (PyModule_AddObjectRef(module, "_initialized", initialized) != 0) { + return -1; + } + return 0; }