From 0939abc3da7319fbfdcb55333828531f31201995 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 11 Sep 2025 12:51:08 +0100 Subject: [PATCH] Add a scoped log section that can be used with `with:` --- util/test/rdtest/logging.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/util/test/rdtest/logging.py b/util/test/rdtest/logging.py index 5ec44211f..d450d3a91 100644 --- a/util/test/rdtest/logging.py +++ b/util/test/rdtest/logging.py @@ -94,6 +94,22 @@ class TestLogger: self.dedent() self.rawprint("<< Section {}".format(name)) + def auto_section(self, name: str): + class ScopedSection(): + def __init__(self, logger: TestLogger, name: str): + self.name = name + self.logger = logger + + def __enter__(self): + self.logger.begin_section(name) + + def __exit__(self, exc_type, exc_value, traceback): + if exc_value is not None: + self.logger.failure(exc_value) + self.logger.end_section(name) + + return ScopedSection(self, name) + def inline_file(self, name: str, path: str, with_stdout: bool = False): self.rawprint(">> Raw {}".format(name)) self.indent()