Made TestHarness a context manager to ensure files get closed.

pull/5527/head
Jussi Pakkanen 5 years ago
parent 49e9e0179c
commit b2cdf528b8
  1. 13
      mesonbuild/mtest.py

@ -641,10 +641,21 @@ class TestHarness:
self.suites = list(ss)
def __del__(self) -> None:
self.close_logfiles()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback) -> None:
self.close_logfiles()
def close_logfiles(self) -> None:
if self.logfile:
self.logfile.close()
self.logfile = None
if self.jsonlogfile:
self.jsonlogfile.close()
self.jsonlogfile = None
def merge_suite_options(self, options: argparse.Namespace, test: 'TestSerialisation') -> typing.Dict[str, str]:
if ':' in options.setup:
@ -1012,8 +1023,8 @@ def run(options: argparse.Namespace) -> int:
if not rebuild_all(options.wd):
return 1
with TestHarness(options) as th:
try:
th = TestHarness(options)
if options.list:
return list_tests(th)
if not options.args:

Loading…
Cancel
Save