From 0d015895debd63b937f1b3ee10cb3a73aa180a8f Mon Sep 17 00:00:00 2001 From: Stefan Hertrampf Date: Fri, 5 Apr 2024 08:42:30 +0200 Subject: [PATCH] nixos/test-driver: separate the subtest log call We do not use the generic "nested" function but introduce a separate subtest log call. This will later allow us to track subtests and account logs to specific subtests. --- nixos/lib/test-driver/test_driver/driver.py | 2 +- nixos/lib/test-driver/test_driver/logger.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nixos/lib/test-driver/test_driver/driver.py b/nixos/lib/test-driver/test_driver/driver.py index f792c0459199..7dfbfdcf1c2a 100644 --- a/nixos/lib/test-driver/test_driver/driver.py +++ b/nixos/lib/test-driver/test_driver/driver.py @@ -99,7 +99,7 @@ class Driver: def subtest(self, name: str) -> Iterator[None]: """Group logs under a given test name""" - with rootlog.nested("subtest: " + name): + with rootlog.subtest(name): try: yield return True diff --git a/nixos/lib/test-driver/test_driver/logger.py b/nixos/lib/test-driver/test_driver/logger.py index 0b0623bddfa1..1b802f992f64 100644 --- a/nixos/lib/test-driver/test_driver/logger.py +++ b/nixos/lib/test-driver/test_driver/logger.py @@ -79,6 +79,11 @@ class Logger: except Empty: pass + @contextmanager + def subtest(self, name: str, attributes: Dict[str, str] = {}) -> Iterator[None]: + with self.nested("subtest: " + name, attributes): + yield + @contextmanager def nested(self, message: str, attributes: Dict[str, str] = {}) -> Iterator[None]: self._eprint(