From 816d952777e20ba06624316aff40ba0708b8bdcc Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Thu, 16 Apr 2026 11:27:30 +0200 Subject: [PATCH] unittest: Remove f-strings. This commit removes usage of f-strings from the unittest module, in favour to the old printf-style raw string formatting operations. The module is a bit special since it is meant to also validate the behaviour of MicroPython interpreters, and those may come with any combination of configuration options. For example, f-strings are not available by default on some feature levels, and thus the test suite won't run cleanly on certain targets unless the support for that feature is explicitly enabled. See the discussion at https://github.com/micropython/micropython/pull/19111 for more information. Signed-off-by: Alessandro Gatti --- python-stdlib/unittest/manifest.py | 2 +- python-stdlib/unittest/unittest/__init__.py | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/python-stdlib/unittest/manifest.py b/python-stdlib/unittest/manifest.py index a01bbb8e6..fea2a87f2 100644 --- a/python-stdlib/unittest/manifest.py +++ b/python-stdlib/unittest/manifest.py @@ -1,3 +1,3 @@ -metadata(version="0.10.4") +metadata(version="0.10.5") package("unittest") diff --git a/python-stdlib/unittest/unittest/__init__.py b/python-stdlib/unittest/unittest/__init__.py index 61b315788..8014e2828 100644 --- a/python-stdlib/unittest/unittest/__init__.py +++ b/python-stdlib/unittest/unittest/__init__.py @@ -1,5 +1,4 @@ import io -import os import sys try: @@ -49,10 +48,10 @@ def __exit__(self, *exc_info): global __test_result__, __current_test__ test_details = __current_test__ if self.msg: - test_details += (f" [{self.msg}]",) + test_details += (" [%s]" % self.msg,) if self.params: - detail = ", ".join(f"{k}={v}" for k, v in self.params.items()) - test_details += (f" ({detail})",) + detail = ", ".join("%s=%s" % k_v for k_v in self.params.items()) + test_details += (" (%s)" % detail,) _handle_test_exception(test_details, __test_result__, exc_info, False) # Suppress the exception as we've captured it above @@ -310,7 +309,7 @@ def printErrorList(self, lst): for c, e in lst: detail = " ".join((str(i) for i in c)) print("======================================================================") - print(f"FAIL: {detail}") + print("FAIL:", detail) print(sep) print(e) @@ -391,7 +390,7 @@ def run_one(test_function): print("%s (%s) ..." % (name, suite_name), end="") set_up() __test_result__ = test_result - test_container = f"({suite_name})" + test_container = "(%s)" % suite_name __current_test__ = (name, test_container) try: test_result._newFailures = 0