From: Eli Bendersky Date: Tue, 2 Aug 2011 03:24:31 +0000 (+0300) Subject: Issue #11049: fix test_forget to work on installed Python, by using a temporary modul... X-Git-Tag: v3.3.0a1~1781 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8db645f72283c3a1d482210b43bfb774a2cbf2b3;p=thirdparty%2FPython%2Fcpython.git Issue #11049: fix test_forget to work on installed Python, by using a temporary module for import/forget --- diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 6322754a8328..589f4828e49d 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()