Skip to content

Commit 8320850

Browse files
vuanhphungIsaac
andcommitted
test: skip the HTTP import guard when the kernel wheel is missing
The kernel backend re-raises a missing databricks_sql_kernel as an ImportError, so look for the missing extra along the exception chain. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
1 parent 34a7759 commit 8320850

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎tests/unit/test_lazy_http_import.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ def test_module_does_not_import_http_client_libraries(module_name):
3737
import sys
3838
try:
3939
import {module_name} # noqa: F401
40-
except ModuleNotFoundError as e:
41-
if e.name not in {_OPTIONAL_DEPS!r}:
40+
except ImportError as e:
41+
# The kernel backend re-raises a missing wheel as a friendlier
42+
# ImportError, so look for the missing extra along the chain.
43+
cause = e
44+
while cause is not None and not (
45+
isinstance(cause, ModuleNotFoundError)
46+
and cause.name in {_OPTIONAL_DEPS!r}
47+
):
48+
cause = cause.__cause__ or cause.__context__
49+
if cause is None:
4250
raise
43-
print(e.name)
51+
print(cause.name)
4452
sys.exit({_MISSING_OPTIONAL_DEP})
4553
loaded = [m for m in {UNWANTED!r} if m in sys.modules]
4654
print(loaded)

0 commit comments

Comments
 (0)