run-tests: use a context manager for file I/O in TextTestRunner
authorBryan O'Sullivan <bryano@fb.com>
Tue, 12 Jan 2016 14:49:10 -0800
changeset 27777 47ac135113ec
parent 27776 6fe2da48a6dd
child 27778 4d10600c3f08
run-tests: use a context manager for file I/O in TextTestRunner
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: