1 """Test context that wraps Tinc instances and terminates them on exit."""
10 """Test context. Allows you to obtain Tinc instances which are automatically
11 stopped (and killed if necessary) at __exit__. Should be wrapped in `with`
12 statements (like the built-in `open`). Should be used sparingly (as it usually
13 happens, thanks to Windows: service registration and removal is quite slow,
14 which makes tests take a long time to run, especially on modest CI VMs).
20 def __init__(self, name: str) -> None:
24 def node(self, addr: str = "") -> Tinc:
25 """Create a Tinc instance and remember it for termination on exit."""
26 node = Tinc(addr=addr)
27 self._nodes.append(node)
30 def __str__(self) -> str:
33 def __enter__(self) -> "Test":
34 log.info("RUNNING TEST: %s", self.name)
37 def __exit__(self, exc_type, exc_val, exc_tb) -> None:
38 for node in self._nodes:
40 log.info("FINISHED TEST: %s", self.name)