diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2020-11-20 08:57:24 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-12-27 13:55:33 +0100 |
commit | a166df1f96d09d0785ec7b170e2fcac8d7b97b9a (patch) | |
tree | ad46d4b99423bc02b968e83b893fd6b87e7427c7 | |
parent | 109cde4ddca2ee59d71f5ee751797d26eb316f77 (diff) | |
download | meson-a166df1f96d09d0785ec7b170e2fcac8d7b97b9a.zip meson-a166df1f96d09d0785ec7b170e2fcac8d7b97b9a.tar.gz meson-a166df1f96d09d0785ec7b170e2fcac8d7b97b9a.tar.bz2 |
mtest: do not use __del__
Use try/finally instead of destructors to ensure that log files are closed.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | mesonbuild/mtest.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index d284326..8956dd8 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -923,9 +923,6 @@ class TestHarness: ss.add(s) self.suites = list(ss) - def __del__(self) -> None: - self.close_logfiles() - def __enter__(self) -> 'TestHarness': return self @@ -1173,7 +1170,7 @@ class TestHarness: return tests - def open_log_files(self) -> None: + def open_logfiles(self) -> None: if not self.options.logbase or self.options.verbose: return @@ -1224,15 +1221,18 @@ class TestHarness: return test.name def run_tests(self, tests: T.List[TestSerialisation]) -> None: - # Replace with asyncio.run once we can require Python 3.7 - loop = asyncio.get_event_loop() - loop.run_until_complete(self._run_tests(tests)) + try: + self.open_logfiles() + # Replace with asyncio.run once we can require Python 3.7 + loop = asyncio.get_event_loop() + loop.run_until_complete(self._run_tests(tests)) + finally: + self.close_logfiles() async def _run_tests(self, tests: T.List[TestSerialisation]) -> None: semaphore = asyncio.Semaphore(self.options.num_processes) futures = deque() # type: T.Deque[asyncio.Future] running_tests = dict() # type: T.Dict[asyncio.Future, str] - self.open_log_files() startdir = os.getcwd() if self.options.wd: os.chdir(self.options.wd) |