Skip to content

Commit 86dd495

Browse files
cathleenyIsaac
andcommitted
test: share the fake kernel stub in test_kernel_fetch_size
test_kernel_fetch_size.py installed its own databricks_sql_kernel stub with a separate KernelError class. When that file was imported before test_kernel_client.py, client.py bound the wrong class and two client tests failed. Reuse test_kernel_client.py's stub and assert both files see the same KernelError. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
1 parent c5b633a commit 86dd495

1 file changed

Lines changed: 15 additions & 32 deletions

File tree

‎tests/unit/test_kernel_fetch_size.py‎

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99
to the kernel statement: the kernel/SEA transport controls chunk size;
1010
- ``row_limit`` is threaded to the kernel statement's ``set_row_limit``.
1111
12-
No network and no Rust extension dependency: a fake kernel module is
13-
installed before import (same approach as ``test_kernel_client.py``) and
14-
the result-set tests drive ``KernelResultSet`` with a fake handle.
12+
No network and no Rust extension dependency: ``test_kernel_client.py``'s
13+
fake kernel module is installed before import, and the result-set tests
14+
drive ``KernelResultSet`` with a fake handle.
1515
"""
1616

1717
from __future__ import annotations
1818

19-
import sys
20-
import types
21-
from typing import Optional
2219
from unittest.mock import MagicMock
2320

2421
import pytest
@@ -28,38 +25,24 @@
2825
pa = pytest.importorskip("pyarrow")
2926

3027

31-
# Install the same session-global fake ``databricks_sql_kernel`` stub
32-
# used by test_kernel_client.py (client.py imports the extension at
33-
# module import time). ``setdefault`` keeps it idempotent when both
34-
# files run in one pytest session.
35-
_fake_kernel_module = types.ModuleType("databricks_sql_kernel")
36-
37-
38-
class _FakeKernelError(Exception):
39-
def __init__(self, code: str = "Unknown", message: str = "boom") -> None:
40-
super().__init__(message)
41-
self.code = code
42-
self.message = message
43-
self.sql_state = None
44-
self.error_code = None
45-
self.vendor_code = None
46-
self.http_status = None
47-
self.retryable = False
48-
self.query_id = None
49-
self.diagnostic_info: Optional[str] = None
50-
self.display_message: Optional[str] = None
51-
self.error_details_json: Optional[str] = None
52-
53-
54-
_fake_kernel_module.KernelError = _FakeKernelError # type: ignore[attr-defined]
55-
_fake_kernel_module.Session = MagicMock() # type: ignore[attr-defined]
56-
sys.modules.setdefault("databricks_sql_kernel", _fake_kernel_module)
28+
# Reuse test_kernel_client.py's session-global fake
29+
# ``databricks_sql_kernel`` stub (client.py imports the extension at
30+
# module import time). Importing that module installs its stub, so both
31+
# files share one ``KernelError`` class in any collection order.
32+
import tests.unit.test_kernel_client as _shared_kernel_stub # noqa: E402
5733

5834
from databricks.sql.auth.authenticators import AccessTokenAuthProvider
5935
from databricks.sql.backend.kernel import client as kernel_client
6036
from databricks.sql.backend.kernel.result_set import KernelResultSet
6137
from databricks.sql.backend.types import CommandId
6238

39+
40+
def test_shares_kernel_stub_with_client_tests():
41+
"""client.py must bind the same fake ``KernelError`` that
42+
test_kernel_client.py raises, whichever file pytest imports first."""
43+
assert kernel_client._kernel.KernelError is _shared_kernel_stub._FakeKernelError
44+
45+
6346
# ---------------------------------------------------------------------------
6447
# Helpers
6548
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)