changeset 27777:47ac135113ec

run-tests: use a context manager for file I/O in TextTestRunner
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 12 Jan 2016 14:49:10 -0800
parents 6fe2da48a6dd
children 4d10600c3f08
files tests/run-tests.py
diffstat 1 files changed, 1 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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: