summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-11-06 13:34:38 +1100
committerDamien George <damien@micropython.org>2025-11-19 13:26:51 +1100
commit8b7d9819b72f5c07ece0eefff556bf54bc35a161 (patch)
treec907fcc5c3177f59b29f474e06518e25f1207afe
parent787d85e0001089eb92f1c3643f29c14b3273b795 (diff)
tests/import: Make import_override and pkg7 tests behave under CPython.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--tests/import/import_override.py4
-rw-r--r--tests/import/pkg7/subpkg1/subpkg2/mod3.py4
2 files changed, 7 insertions, 1 deletions
diff --git a/tests/import/import_override.py b/tests/import/import_override.py
index 029ebe54c..0144e78cb 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 b0f4279fc..f7f4c1e65 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")