From 9d9e099cdb893791ec0266ed37d027e78407ef4b Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 25 Sep 2025 13:35:38 +0200 Subject: [PATCH] test/infamy: slight improvement to tap.py::Test.__exit__() Before this change: ok 2 - Configure basic end-device firewall not ok 3 - Verify unused interface assigned to default zone # Exiting (2025-09-25 11:33:00) # Traceback (most recent call last): # File "/home/jocke/src/x-misc/test/./case/infix_firewall/basic/test.py", line 127, in # assert unused_if not in public_zone["interface"], \ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # AssertionError: Unused interface e4 should be in default zone 'public', got interfaces: ['e2', 'e3', 'e5', 'e7', 'e8'] After this change: ok 2 - Configure basic end-device firewall not ok 3 - Verify unused interface assigned to default zone # Exiting (2025-09-25 11:35:00) # File "/home/jocke/src/x-misc/test/./case/infix_firewall/basic/test.py", line 127, in # assert unused_if not in public_zone["interface"], \ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Unused interface e4 should be in default zone 'public', got interfaces: ['e2', 'e3', 'e5', 'e7', 'e8'] Slightly shorter and arguably easier to read for a non-pythonic human. Signed-off-by: Joachim Wiberg --- test/infamy/tap.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/infamy/tap.py b/test/infamy/tap.py index 7e46c973..b1938326 100644 --- a/test/infamy/tap.py +++ b/test/infamy/tap.py @@ -30,7 +30,7 @@ class Test: self.out.flush() return self - def __exit__(self, _, e, __): + def __exit__(self, t, e, tb): now = datetime.datetime.now().strftime("%F %T") self.out.write(f"# Exiting ({now})\n") self.out.flush() @@ -40,12 +40,16 @@ class Test: if not e: self._not_ok("Missing explicit test result\n") else: - if type(e) in (TestPass, TestSkip): + if t in (TestPass, TestSkip): self.out.write(f"{self.steps}..{self.steps}\n") self.out.flush() raise SystemExit(0) - - traceback.print_exception(e, file=self.commenter) + if t is AssertionError: + traceback.print_tb(tb, file=self.commenter) + self.out.write(f"{str(e)}\n") + self.out.flush() + else: + traceback.print_exception(e, file=self.commenter) if type(e) is subprocess.CalledProcessError: print("Failing subprocess stdout:\n", e.stdout)