tests/import: Make import_override and pkg7 tests behave under CPython.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-11-06 13:34:38 +11:00
parent 787d85e000
commit 8b7d9819b7
2 changed files with 7 additions and 1 deletions

View File

@@ -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:

View File

@@ -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")