run-tests: use a context manager for file I/O
authorBryan O'Sullivan <bryano@fb.com>
Tue, 12 Jan 2016 14:29:57 -0800
changeset 27773 bf45edfa9d90
parent 27772 00bd72629a45
child 27774 8ceaaf63ca80
run-tests: use a context manager for file I/O
tests/run-tests.py
--- a/tests/run-tests.py	Tue Jan 12 14:29:34 2016 -0800
+++ b/tests/run-tests.py	Tue Jan 12 14:29:57 2016 -0800
@@ -1716,8 +1716,7 @@
                 if json is None:
                     raise ImportError("json module not installed")
                 jsonpath = os.path.join(self._runner._testdir, 'report.json')
-                fp = open(jsonpath, 'w')
-                try:
+                with open(jsonpath, 'w') as fp:
                     timesd = {}
                     for tdata in result.times:
                         test = tdata[0]
@@ -1741,8 +1740,6 @@
                             outcome[tc.name] = tres
                     jsonout = json.dumps(outcome, sort_keys=True, indent=4)
                     fp.writelines(("testreport =", jsonout))
-                finally:
-                    fp.close()
 
             self._runner._checkhglib('Tested')