From 8db645f72283c3a1d482210b43bfb774a2cbf2b3 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 2 Aug 2011 06:24:31 +0300 Subject: Issue #11049: fix test_forget to work on installed Python, by using a temporary module for import/forget --- Lib/test/test_support.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 6322754..589f482 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -55,9 +55,17 @@ class TestSupport(unittest.TestCase): support.rmtree(TESTDIRN) def test_forget(self): - import smtplib - support.forget("smtplib") - self.assertNotIn("smtplib", sys.modules) + mod_filename = TESTFN + '.py' + with open(mod_filename, 'w') as f: + print('foo = 1', file=f) + try: + mod = __import__(TESTFN) + self.assertIn(TESTFN, sys.modules) + + support.forget(TESTFN) + self.assertNotIn(TESTFN, sys.modules) + finally: + support.unlink(mod_filename) def test_HOST(self): s = socket.socket() -- cgit v0.12