diff --git a/test/infamy/tap.py b/test/infamy/tap.py index 42a2ed61..5c805a02 100644 --- a/test/infamy/tap.py +++ b/test/infamy/tap.py @@ -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")