diff options
author | Eli Bendersky <eliben@gmail.com> | 2011-08-02 03:24:31 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2011-08-02 03:24:31 (GMT) |
commit | 8db645f72283c3a1d482210b43bfb774a2cbf2b3 (patch) | |
tree | f93504492253e08d37b79a7d66fcbff4ea7404d9 | |
parent | d9c665b60e655533ecdb38a443a801b0d2e6f324 (diff) | |
download | cpython-8db645f72283c3a1d482210b43bfb774a2cbf2b3.zip cpython-8db645f72283c3a1d482210b43bfb774a2cbf2b3.tar.gz cpython-8db645f72283c3a1d482210b43bfb774a2cbf2b3.tar.bz2 |
Issue #11049: fix test_forget to work on installed Python, by using a temporary module for import/forget
-rw-r--r-- | Lib/test/test_support.py | 14 |
1 files 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() |