# HG changeset patch # User Bryan O'Sullivan # Date 1452638950 28800 # Node ID 47ac135113ec944826db6e76b7b8af76e4a166e1 # Parent 6fe2da48a6dd129c3b14599d2312582fe1f2630d run-tests: use a context manager for file I/O in TextTestRunner diff -r 6fe2da48a6dd -r 47ac135113ec tests/run-tests.py --- a/tests/run-tests.py Tue Jan 12 14:48:27 2016 -0800 +++ b/tests/run-tests.py Tue Jan 12 14:49:10 2016 -0800 @@ -1681,8 +1681,7 @@ self.stream.writeln('Errored %s: %s' % (test.name, msg)) if self._runner.options.xunit: - xuf = open(self._runner.options.xunit, 'wb') - try: + with open(self._runner.options.xunit, 'wb') as xuf: timesd = dict((t[0], t[3]) for t in result.times) doc = minidom.Document() s = doc.createElement('testsuite') @@ -1709,8 +1708,6 @@ t.appendChild(cd) s.appendChild(t) xuf.write(doc.toprettyxml(indent=' ', encoding='utf-8')) - finally: - xuf.close() if self._runner.options.json: if json is None: