From 7749075a96f756e6ce236ab72148d1eec1f7ba2d Mon Sep 17 00:00:00 2001 From: Terry Date: Wed, 11 Jun 2025 16:53:40 -0300 Subject: [PATCH] test: adds a quick test to ensure both psycopg and psycopg2 drivers are compatible --- modules/postgres/tests/test_postgres.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/postgres/tests/test_postgres.py b/modules/postgres/tests/test_postgres.py index c2e7d9822..93b99d25f 100644 --- a/modules/postgres/tests/test_postgres.py +++ b/modules/postgres/tests/test_postgres.py @@ -133,3 +133,21 @@ def test_none_driver_urls(): url = container.get_connection_url(driver=None) assert url == expected_url + + +def test_psycopg_versions(): + """Test that both psycopg2 and psycopg (v2 and v3) work with the container.""" + + postgres_container = PostgresContainer("postgres:16-alpine", driver="psycopg2") + with postgres_container as postgres: + engine = sqlalchemy.create_engine(postgres.get_connection_url()) + with engine.begin() as connection: + result = connection.execute(sqlalchemy.text("SELECT 1 as test")) + assert result.scalar() == 1 + + postgres_container = PostgresContainer("postgres:16-alpine", driver="psycopg") + with postgres_container as postgres: + engine = sqlalchemy.create_engine(postgres.get_connection_url()) + with engine.begin() as connection: + result = connection.execute(sqlalchemy.text("SELECT 1 as test")) + assert result.scalar() == 1