aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mtest.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-06-21 18:40:05 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2019-06-21 19:59:09 +0300
commitb2cdf528b81d741e96767a88d86cb0d042d7b2ff (patch)
tree4b5b445cd82ceb3064e3f59b27fbab56c98f827e /mesonbuild/mtest.py
parent49e9e0179ce33cd4c99309912ea71dfd3460a714 (diff)
downloadmeson-b2cdf528b81d741e96767a88d86cb0d042d7b2ff.zip
meson-b2cdf528b81d741e96767a88d86cb0d042d7b2ff.tar.gz
meson-b2cdf528b81d741e96767a88d86cb0d042d7b2ff.tar.bz2
Made TestHarness a context manager to ensure files get closed.
Diffstat (limited to 'mesonbuild/mtest.py')
-rw-r--r--mesonbuild/mtest.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index b09de16..1dca075 100644
--- a/mesonbuild/mtest.py
+++ b/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,20 +1023,20 @@ def run(options: argparse.Namespace) -> int:
if not rebuild_all(options.wd):
return 1
- try:
- th = TestHarness(options)
- if options.list:
- return list_tests(th)
- if not options.args:
- return th.doit()
- return th.run_special()
- except TestException as e:
- print('Meson test encountered an error:\n')
- if os.environ.get('MESON_FORCE_BACKTRACE'):
- raise e
- else:
- print(e)
- return 1
+ with TestHarness(options) as th:
+ try:
+ if options.list:
+ return list_tests(th)
+ if not options.args:
+ return th.doit()
+ return th.run_special()
+ except TestException as e:
+ print('Meson test encountered an error:\n')
+ if os.environ.get('MESON_FORCE_BACKTRACE'):
+ raise e
+ else:
+ print(e)
+ return 1
def run_with_args(args: typing.List[str]) -> int:
parser = argparse.ArgumentParser(prog='meson test')