Skip to content

Commit 3b9e8e4

Browse files
authored
test(modules): Adds postgres test ensure both drivers are compatible (#828)
Once the new docs site is up I will likely add a demo there, but for the moment a quick basic unit test to ensure both are properly working.
1 parent dafcbed commit 3b9e8e4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

modules/postgres/tests/test_postgres.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,21 @@ def test_none_driver_urls():
133133

134134
url = container.get_connection_url(driver=None)
135135
assert url == expected_url
136+
137+
138+
def test_psycopg_versions():
139+
"""Test that both psycopg2 and psycopg (v2 and v3) work with the container."""
140+
141+
postgres_container = PostgresContainer("postgres:16-alpine", driver="psycopg2")
142+
with postgres_container as postgres:
143+
engine = sqlalchemy.create_engine(postgres.get_connection_url())
144+
with engine.begin() as connection:
145+
result = connection.execute(sqlalchemy.text("SELECT 1 as test"))
146+
assert result.scalar() == 1
147+
148+
postgres_container = PostgresContainer("postgres:16-alpine", driver="psycopg")
149+
with postgres_container as postgres:
150+
engine = sqlalchemy.create_engine(postgres.get_connection_url())
151+
with engine.begin() as connection:
152+
result = connection.execute(sqlalchemy.text("SELECT 1 as test"))
153+
assert result.scalar() == 1

0 commit comments

Comments
 (0)