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>
pull/8001/head
Paolo Bonzini 4 years ago
parent 109cde4ddc
commit a166df1f96
  1. 10
      mesonbuild/mtest.py

@ -923,9 +923,6 @@ class TestHarness:
ss.add(s) ss.add(s)
self.suites = list(ss) self.suites = list(ss)
def __del__(self) -> None:
self.close_logfiles()
def __enter__(self) -> 'TestHarness': def __enter__(self) -> 'TestHarness':
return self return self
@ -1173,7 +1170,7 @@ class TestHarness:
return tests return tests
def open_log_files(self) -> None: def open_logfiles(self) -> None:
if not self.options.logbase or self.options.verbose: if not self.options.logbase or self.options.verbose:
return return
@ -1224,15 +1221,18 @@ class TestHarness:
return test.name return test.name
def run_tests(self, tests: T.List[TestSerialisation]) -> None: def run_tests(self, tests: T.List[TestSerialisation]) -> None:
try:
self.open_logfiles()
# Replace with asyncio.run once we can require Python 3.7 # Replace with asyncio.run once we can require Python 3.7
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(self._run_tests(tests)) loop.run_until_complete(self._run_tests(tests))
finally:
self.close_logfiles()
async def _run_tests(self, tests: T.List[TestSerialisation]) -> None: async def _run_tests(self, tests: T.List[TestSerialisation]) -> None:
semaphore = asyncio.Semaphore(self.options.num_processes) semaphore = asyncio.Semaphore(self.options.num_processes)
futures = deque() # type: T.Deque[asyncio.Future] futures = deque() # type: T.Deque[asyncio.Future]
running_tests = dict() # type: T.Dict[asyncio.Future, str] running_tests = dict() # type: T.Dict[asyncio.Future, str]
self.open_log_files()
startdir = os.getcwd() startdir = os.getcwd()
if self.options.wd: if self.options.wd:
os.chdir(self.options.wd) os.chdir(self.options.wd)

Loading…
Cancel
Save