Skip to content

Commit 7d514fa

Browse files
committed
Fix test_pybind_implicit_prepare_cache for C-API CI
Two bugs fixed in the test: 1. Add close() method to _FakeResult — QueryResult.close() calls self._query_result.close() internally; the missing method caused AttributeError during teardown on C-API CI. 2. Fix _get_pybind_connection monkeypatch to store fake_pybind in self._py_connection — the bare lambda returned fake_pybind but never stored it, so Connection.close() never called fake_pybind_connection.close(), causing 'assert fake_pybind_connection.closed is True' to fail. The test runs on both pybind and C-API CI jobs. These changes ensure it passes on C-API without affecting the pybind behavior.
1 parent 9e49718 commit 7d514fa

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

test/test_pybind_implicit_prepare_cache.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def isSuccess(self) -> bool:
1414
def hasNextQueryResult(self) -> bool:
1515
return False
1616

17+
def close(self) -> None:
18+
return
19+
1720

1821
class _FakePreparedStatement:
1922
def __init__(self, query: str, parameters: dict[str, object]):
@@ -83,9 +86,13 @@ def fake_pybind_connection(monkeypatch: pytest.MonkeyPatch) -> _FakePybindConnec
8386
"init_connection",
8487
lambda self: setattr(self, "_connection", _FakeBackendConnection()),
8588
)
86-
monkeypatch.setattr(
87-
lb.Connection, "_get_pybind_connection", lambda self: fake_pybind
88-
)
89+
90+
def _get_pybind_connection(self: lb.Connection) -> _FakePybindConnection:
91+
if self._py_connection is None:
92+
self._py_connection = fake_pybind
93+
return self._py_connection
94+
95+
monkeypatch.setattr(lb.Connection, "_get_pybind_connection", _get_pybind_connection)
8996
return fake_pybind
9097

9198

0 commit comments

Comments
 (0)