[Python-checkins] test_builtin: TestExecFile removes created file (#4525)
Victor Stinner
webhook-mailer at python.org
Thu Nov 23 12:23:40 EST 2017
https://github.com/python/cpython/commit/2d5890eda62477982361405d3486e57f590c78ae
commit: 2d5890eda62477982361405d3486e57f590c78ae
branch: 2.7
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-11-23T18:23:37+01:00
summary:
test_builtin: TestExecFile removes created file (#4525)
Fix the following warning:
Warning -- files was modified by test_builtin
Before: []
After: ['@test_19422_tmp']
1 test altered the execution environment:
test_builtin
files:
M Lib/test/test_builtin.py
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index c9347e96aa1..5396838f3d2 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1593,18 +1593,28 @@ def test_bytearray_translate(self):
self.assertRaises(ValueError, x.translate, "1", 1)
self.assertRaises(TypeError, x.translate, "1"*256, 1)
+
+def create_exec_script(filename):
+ with open(filename, 'w') as f:
+ f.write('z = z+1\n')
+ f.write('z = z*2\n')
+
+
class TestExecFile(unittest.TestCase):
# Done outside of the method test_z to get the correct scope
z = 0
- f = open(TESTFN, 'w')
- f.write('z = z+1\n')
- f.write('z = z*2\n')
- f.close()
- with check_py3k_warnings(("execfile.. not supported in 3.x",
- DeprecationWarning)):
- execfile(TESTFN)
+ try:
+ create_exec_script(TESTFN)
+ with check_py3k_warnings(("execfile.. not supported in 3.x",
+ DeprecationWarning)):
+ execfile(TESTFN)
+ finally:
+ unlink(TESTFN)
def test_execfile(self):
+ self.addCleanup(unlink, TESTFN)
+ create_exec_script(TESTFN)
+
globals = {'a': 1, 'b': 2}
locals = {'b': 200, 'c': 300}
More information about the Python-checkins
mailing list