Skip to content

Commit

Permalink
test: infamy: Add optional test cleanup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattiaswal committed Dec 19, 2024
1 parent 8e38b34 commit ffa8a0a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/infamy/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ def __init__(self, output=sys.stdout):
if self.out == sys.stdout:
sys.stdout = self.commenter

self.test_cleanup=[]
self.steps = 0

def set_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")
Expand All @@ -26,7 +35,7 @@ def __exit__(self, _, e, __):
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")
Expand Down

0 comments on commit ffa8a0a

Please sign in to comment.