test harness: use try-finally in contextmanagers