##// END OF EJS Templates
Leak less files during test....
Matthias Bussonnier -
Show More
@@ -270,20 +270,25 b' class TempFileMixin(object):'
270 def mktmp(self, src, ext='.py'):
270 def mktmp(self, src, ext='.py'):
271 """Make a valid python temp file."""
271 """Make a valid python temp file."""
272 fname, f = temp_pyfile(src, ext)
272 fname, f = temp_pyfile(src, ext)
273 self.tmpfile = f
273 if not hasattr(self, 'tmps'):
274 self.tmps=[]
275 self.tmps.append((f, fname))
274 self.fname = fname
276 self.fname = fname
275
277
276 def tearDown(self):
278 def tearDown(self):
277 if hasattr(self, 'tmpfile'):
279 # If the tmpfile wasn't made because of skipped tests, like in
278 # If the tmpfile wasn't made because of skipped tests, like in
280 # win32, there's nothing to cleanup.
279 # win32, there's nothing to cleanup.
281 if hasattr(self, 'tmps'):
280 self.tmpfile.close()
282 for f,fname in self.tmps:
281 try:
283 # If the tmpfile wasn't made because of skipped tests, like in
282 os.unlink(self.fname)
284 # win32, there's nothing to cleanup.
283 except:
285 f.close()
284 # On Windows, even though we close the file, we still can't
286 try:
285 # delete it. I have no clue why
287 os.unlink(fname)
286 pass
288 except:
289 # On Windows, even though we close the file, we still can't
290 # delete it. I have no clue why
291 pass
287
292
288 def __enter__(self):
293 def __enter__(self):
289 return self
294 return self
General Comments 0
You need to be logged in to leave comments. Login now