diff --git a/IPython/testing/tests/test_tools.py b/IPython/testing/tests/test_tools.py index 4fa5c96..2a6b9e4 100644 --- a/IPython/testing/tests/test_tools.py +++ b/IPython/testing/tests/test_tools.py @@ -62,9 +62,8 @@ def test_parser(): def test_temp_pyfile(): src = 'pass\n' - fname, fh = tt.temp_pyfile(src) + fname = tt.temp_pyfile(src) assert os.path.isfile(fname) - fh.close() with open(fname) as fh2: src2 = fh2.read() nt.assert_equal(src2, src) diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py index 1d16f11..b2d7df4 100644 --- a/IPython/testing/tools.py +++ b/IPython/testing/tools.py @@ -269,20 +269,19 @@ class TempFileMixin(object): def mktmp(self, src, ext='.py'): """Make a valid python temp file.""" - fname, f = temp_pyfile(src, ext) + fname = temp_pyfile(src, ext) if not hasattr(self, 'tmps'): self.tmps=[] - self.tmps.append((f, fname)) + self.tmps.append(fname) self.fname = fname def tearDown(self): # If the tmpfile wasn't made because of skipped tests, like in # win32, there's nothing to cleanup. if hasattr(self, 'tmps'): - for f,fname in self.tmps: + for fname in self.tmps: # If the tmpfile wasn't made because of skipped tests, like in # win32, there's nothing to cleanup. - f.close() try: os.unlink(fname) except: diff --git a/IPython/utils/io.py b/IPython/utils/io.py index b59a1a1..fab9bae 100644 --- a/IPython/utils/io.py +++ b/IPython/utils/io.py @@ -205,10 +205,10 @@ def temp_pyfile(src, ext='.py'): It is the caller's responsibility to close the open file and unlink it. """ fname = tempfile.mkstemp(ext)[1] - f = open(fname,'w') - f.write(src) - f.flush() - return fname, f + with open(fname,'w') as f: + f.write(src) + f.flush() + return fname @undoc def atomic_writing(*args, **kwargs):