mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-31 13:03:02 +02:00
test: infamy: Add optional test cleanup
If a test need to clean up itself disregarding test status, it can add an optional test-cleanup phase. This is useful if the test in some circomstances leave the device in a bad state. This can be used to restore the unit to its ordinary state.
This commit is contained in:
+10
-1
@@ -13,8 +13,17 @@ class Test:
|
||||
if self.out == sys.stdout:
|
||||
sys.stdout = self.commenter
|
||||
|
||||
self.test_cleanup=[]
|
||||
self.steps = 0
|
||||
|
||||
def push_test_cleanup(self, fn):
|
||||
self.test_cleanup.append(fn)
|
||||
|
||||
def cleanup(self):
|
||||
infamy.netns.IsolatedMacVlans.Cleanup()
|
||||
for test_cleanup in reversed(self.test_cleanup):
|
||||
test_cleanup()
|
||||
|
||||
def __enter__(self):
|
||||
now = datetime.datetime.now().strftime("%F %T")
|
||||
self.out.write(f"# Starting ({now})\n")
|
||||
@@ -26,7 +35,7 @@ class Test:
|
||||
self.out.write(f"# Exiting ({now})\n")
|
||||
self.out.flush()
|
||||
|
||||
infamy.netns.IsolatedMacVlans.Cleanup()
|
||||
self.cleanup()
|
||||
|
||||
if not e:
|
||||
self._not_ok("Missing explicit test result\n")
|
||||
|
||||
Reference in New Issue
Block a user