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.
This commit is contained in:
Marek Marczykowski-Górecki 2018-09-09 02:33:17 +02:00
父節點 c102fa3d68
當前提交 b2cc605f4b
沒有發現已知的金鑰在資料庫的簽署中
GPG 金鑰 ID: 063938BA42CFA724

查看文件

@ -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