From b2cc605f4bf9f9a0c4a6600eeb897517b576ad21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 9 Sep 2018 02:33:17 +0200 Subject: [PATCH] tests: clean local variables from traceback objects System tests are fragile for any object leaks, especially those holding open files. Instead of wrapping all tests with try/finally removing those local variables (as done in qubes.tests.integ.backup for example), apply generic solution: clean all traceback objects from local variables. Those aren't used to generate text report by either test runner (qubes.tests.run and nose2). If one wants to break into debugger and inspect tracebacks interactively, needs to comment out call to cleanup_traceback. --- qubes/tests/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 13555cef..140e7f43 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -379,8 +379,20 @@ class QubesTestCase(unittest.TestCase): self.loop = asyncio.get_event_loop() self.addCleanup(self.cleanup_loop) + self.addCleanup(self.cleanup_traceback) self.addCleanup(qubes.ext.pci._cache_get.cache_clear) + def cleanup_traceback(self): + '''Remove local variables reference from tracebacks to allow garbage + collector to clean all Qubes*() objects, otherwise file descriptors + held by them will leak''' + for test_case, exc_info in self._outcome.errors: + if test_case is not self: + continue + if exc_info is None: + continue + traceback.clear_frames(exc_info[2]) + def cleanup_gc(self): gc.collect() leaked = [obj for obj in gc.get_objects() + gc.garbage