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

Skip to content

Commit 243bff4

Browse files
committed
Clean up junk files left behind by imp.load_source().
1 parent 0c8f664 commit 243bff4

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/test/test_inspect.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def test(assertion, message, *args):
7575
file.write(source)
7676
file.close()
7777

78+
# Note that load_source creates file TESTFN+'c' or TESTFN+'o'.
7879
mod = imp.load_source('testmod', TESTFN)
80+
files_to_clean_up = [TESTFN, TESTFN + 'c', TESTFN + 'o']
7981

8082
def istest(func, exp):
8183
obj = eval(exp)
@@ -204,4 +206,8 @@ def sourcerange(top, bottom):
204206
'(a=7, b=8, c=9, d=3, (e=4, (f=5,)), *g=(), **h={})',
205207
'mod.fr.f_back formatted argvalues')
206208

207-
os.unlink(TESTFN)
209+
for fname in files_to_clean_up:
210+
try:
211+
os.unlink(fname)
212+
except:
213+
pass

0 commit comments

Comments
 (0)