test(snowflake): fix the mock patch target so the suite actually runs - #2603
Conversation
…nt attribute path wren.connector.snowflake imports snowflake.connector inside its functions (kept out of module import time on purpose), so wren.connector.snowflake.snowflake.connector.connect was never a valid mock.patch target — every test using it raised AttributeError. Patch the actual snowflake.connector.connect module path instead, which the function-local import resolves through sys.modules. Also update test_query_with_limit_slices_result to match the connector's LIMIT-pushdown behavior (LIMIT is appended to the SQL sent to Snowflake, not sliced client-side), which the mock patch fix exposed as a second, previously-masked test/implementation mismatch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…an fail Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughSnowflake connector tests now patch the correct connection function and verify that query limits are pushed into SQL without client-side Arrow table slicing. ChangesSnowflake connector tests
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
tests/connectors/test_snowflake.pyhas been silently broken: 11 of its 16 tests fail before their bodies run. This fixes the mock patch target, and one assertion the breakage was hiding.What failure does this repair?
src/wren/connector/snowflake.pyimports the driver inside the functions that use it (import snowflake.connector, with a# noqa: PLC0415), sowren.connector.snowflakenever gains asnowflakeattribute. The tests patch"wren.connector.snowflake.snowflake.connector.connect", a path that does not exist, andmock.patchfails at attribute resolution before the test body executes.The fix patches the real module path,
"snowflake.connector.connect". The function-local import resolves throughsys.modulesat call time, so the connector picks up the patchedconnect. The production import is deliberately function-local — it keeps an optional driver out of module import time — so it is left alone rather than hoisted to make patching convenient.A second, hidden failure surfaced once the tests ran.
test_query_with_limit_slices_resultasserted that the connector fetches a full result and slices it tolimitrows in Python.query()has not done that since LIMIT pushdown landed: it wraps the SQL asSELECT * FROM (...) AS _wren_sub LIMIT nand returns the driver's table unmodified. The assertion was stale and only survived because the whole file was inert. It is nowtest_query_with_limit_pushes_limit_into_sql, asserting the pushdown appears in the SQL handed tocursor.execute. The mocked cursor deliberately returns more rows than the limit — a real Snowflake would honour the pushed-down LIMIT — so the test fails if a client-side slice is ever reintroduced.How is it tested?
tests/connectors/test_snowflake.py: 11 failed / 5 passed → 16 passed.Note this file does not currently run in CI at all — the connector matrix covers only postgres and mysql. It needs no external service (it is fully mocked), so fixing it is a prerequisite to running it in the default jobs.
Regression check:
pytest tests/unit/ --ignore=tests/unit/test_memory.py --ignore=tests/unit/test_mcp_server.py→ 1023 passed, 2 skipped.ruff format --check/ruff checkclean onsrc/and on the touched file.Duplicate check
No open PR touches
tests/connectors/test_snowflake.py. #2593 and #2556 touchsrc/wren/connector/snowflake.py, which this PR does not modify.🤖 Generated with Claude Code
Summary by CodeRabbit