diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index 833bf1989de..d3241918b68 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -317,8 +317,9 @@ def test_builtin(self): def test_with_deleted_parent(self): # see #18681 from html import parser - del sys.modules['html'] - def cleanup(): del sys.modules['html.parser'] + html = sys.modules.pop('html') + def cleanup(): + sys.modules['html'] = html self.addCleanup(cleanup) with self.assertRaisesRegex(ImportError, 'html'): imp.reload(parser)