From 8b7d9819b72f5c07ece0eefff556bf54bc35a161 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 6 Nov 2025 13:34:38 +1100 Subject: [PATCH] tests/import: Make import_override and pkg7 tests behave under CPython. Signed-off-by: Damien George --- tests/import/import_override.py | 4 ++++ tests/import/pkg7/subpkg1/subpkg2/mod3.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/import/import_override.py b/tests/import/import_override.py index 029ebe54c1..0144e78cb9 100644 --- a/tests/import/import_override.py +++ b/tests/import/import_override.py @@ -2,6 +2,10 @@ def custom_import(name, globals, locals, fromlist, level): + # CPython always tries to import _io, so just let that through as-is. + if name == "_io": + return orig_import(name, globals, locals, fromlist, level) + print("import", name, fromlist, level) class M: diff --git a/tests/import/pkg7/subpkg1/subpkg2/mod3.py b/tests/import/pkg7/subpkg1/subpkg2/mod3.py index b0f4279fcf..f7f4c1e65f 100644 --- a/tests/import/pkg7/subpkg1/subpkg2/mod3.py +++ b/tests/import/pkg7/subpkg1/subpkg2/mod3.py @@ -5,7 +5,9 @@ print(mod1.foo) print(bar) # attempted relative import beyond top-level package +# On older versions of CPython (eg 3.8) this is a ValueError, but on +# newer CPython (eg 3.11) and MicroPython it's an ImportError. try: from .... import mod1 -except ImportError: +except (ImportError, ValueError): print("ImportError")