# HG changeset patch # User Bryan O'Sullivan # Date 1452637797 28800 # Node ID bf45edfa9d9076a953b5890bdda533e977cd6d90 # Parent 00bd72629a457dd2b466e8b56fd0872844aff412 run-tests: use a context manager for file I/O diff -r 00bd72629a45 -r bf45edfa9d90 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')