Repository navigation
fix(wren): keep just test collecting without the postgres extra - #2801
Conversation
tests/connectors/test_postgres.py imported psycopg at module level, but psycopg ships only in the optional postgres extra, not in the dev group that `just install` resolves. On the documented setup path the import aborts collection of `pytest tests/`, so `just test` runs zero tests. Skip the module when the extra is absent, the way test_mssql.py already does for pyodbc.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe PostgreSQL test module now checks for ChangesPostgreSQL test collection
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~5 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to Ordinary test collection can skip PostgreSQL-specific tests when the optional dependency is absent; no material merge-blocking risk is identified. Pre-merge checks |
|
goldmedal
left a comment
There was a problem hiding this comment.
Thanks @lihongyuan99 👍
Summary
tests/connectors/test_postgres.py:16didimport psycopgat module level, butpsycopgis only in the optional
postgresextra (core/wren/pyproject.toml:postgres = ["psycopg[binary]>=3"]) and not in thedevgroup thatjust install(
uv sync) resolves. On the setup pathCONTRIBUTING.mdprescribes forcore/wren(
just install && just test), that import is an unhandledModuleNotFoundErrorduringcollection, which aborts the whole pytest session —
just testruns zero tests.This makes the module skip itself when the extra is absent, the way
tests/connectors/test_mssql.py:19already does forpyodbc.What failure does this repair?
Reproduced on
main@fedf182in ajust installenvironment (core/wren, Python3.12.12;
psycopgnot importable,testcontainers/duckdb/orjson/pyarrowpresent):Interrupted: 1 error during collectionmeans no test file runs at all, including theservice-free unit tree.
just testisuv run --no-sync pytest tests/ -v, so this is thedocumented entry point failing, not an exotic selection.
The skip has to be placed before the first-party imports, not just before
psycopg'sold position:
src/wren/connector/postgres.py:19importspsycopgat module level too, sofrom wren.connector.postgres import ...(line 24) would raise the same error one linelater. That is why the following import block carries
# noqa: E402, mirroringtest_mssql.py:25-31.How is it tested?
core/wren/)uv run --no-sync pytest tests/ --collect-only -q2,1922 tests collected, 1 error, session interrupted0,1922 tests collected in 0.79suv run --no-sync pytest tests/connectors/test_postgres.py -q1 skipped in 0.07suv run --no-sync pytest tests/unit/ -q --ignore=tests/unit/test_memory.py --ignore=tests/unit/test_mcp_server.py1 failed, 1519 passed, 2 skipped in 27.65s1 failed, 1519 passed, 2 skipped in 27.56suv run --no-sync pytest tests/connectors/test_postgres.py --collect-only -qwithpsycopg[binary]installed37 tests collecteduv run --no-sync ruff check tests/connectors/test_postgres.pyE402, 3PLC0415)uv run --no-sync ruff format --check tests/connectors/test_postgres.pyThe single unit failure is pre-existing on
mainunder this exact selection(
test_cloud.py::test_create_refuses_without_a_git_identity_before_creating_anything);it was measured on the untouched baseline above. The changed file itself is exercised by
CI's
datasource testsmatrix job, which installs the extra — verified by the37 tests collectedrow, i.e. the skip is a no-op there. I did not run thecontainer-backed tests: this machine has no running Docker daemon.
No test file is added; the red/green is the exit status of the existing collection.
Duplicate check
GET /repos/Canner/WrenAI/pulls?state=open&per_page=100(78 PRs across pages 1-2, page 3 empty) and dumped their files via
GET /pulls/{n}/files(716 rows). One PR touchescore/wren/tests/connectors/:feat(wren): add StarRocks as a first-class data source #2790 adds a new
test_starrocks.py. No open PR touchescore/wren/tests/connectors/test_postgres.py. fix: security hardening, config defaults, and test coverage across connectors and Rust core #2551 and fix: address CodeRabbit v3 — allow UNION queries, document --api-key #2552 touchtests/unit/test_postgres_semicolon_unlimited.py, a different file.mainreports exactly oneerror, and
git log --since=2026-09-01 origin/main -- core/wren/tests/connectors/test_postgres.pyshows no encoding/skip fix landed there. The sibling connector files already either use
pytest.importorskip(test_mssql.py:19,test_canner.py:24) or import packages fromthe
devgroup (testcontainers,duckdb,orjson,pyarrow), so they collect cleanly.Summary by CodeRabbit