Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8db645f

Browse files
committed
Issue #11049: fix test_forget to work on installed Python, by using a temporary module for import/forget
1 parent d9c665b commit 8db645f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/test/test_support.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ def test_rmtree(self):
5555
support.rmtree(TESTDIRN)
5656

5757
def test_forget(self):
58-
import smtplib
59-
support.forget("smtplib")
60-
self.assertNotIn("smtplib", sys.modules)
58+
mod_filename = TESTFN + '.py'
59+
with open(mod_filename, 'w') as f:
60+
print('foo = 1', file=f)
61+
try:
62+
mod = __import__(TESTFN)
63+
self.assertIn(TESTFN, sys.modules)
64+
65+
support.forget(TESTFN)
66+
self.assertNotIn(TESTFN, sys.modules)
67+
finally:
68+
support.unlink(mod_filename)
6169

6270
def test_HOST(self):
6371
s = socket.socket()

0 commit comments

Comments
 (0)