1515pytestmark = pytest .mark .anyio
1616
1717
18- async def test_connect_func () -> None :
18+ async def test_connect_func (dsn : str ) -> None :
1919 """Test that connect function makes new connection pool."""
20- pg_pool = connect_pool (
21- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
22- )
20+ pg_pool = connect_pool (dsn = dsn )
2321
2422 conn = await pg_pool .connection ()
2523 await conn .execute ("SELECT 1" )
2624
2725
28- async def test_pool_dsn_startup () -> None :
26+ async def test_pool_dsn_startup (dsn : str ) -> None :
2927 """Test that connection pool can startup with dsn."""
30- pg_pool = ConnectionPool (
31- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
32- )
28+ pg_pool = ConnectionPool (dsn = dsn )
3329
3430 conn = await pg_pool .connection ()
3531 await conn .execute ("SELECT 1" )
3632
3733
38- async def test_pool_connection (
39- psql_pool : ConnectionPool ,
40- ) -> None :
34+ async def test_pool_connection (psql_pool : ConnectionPool ) -> None :
4135 """Test that ConnectionPool can return single connection from the pool."""
4236 connection = await psql_pool .connection ()
4337 assert isinstance (connection , Connection )
@@ -53,37 +47,29 @@ async def test_pool_connection(
5347)
5448async def test_pool_conn_recycling_method (
5549 conn_recycling_method : ConnRecyclingMethod ,
50+ dsn : str ,
5651) -> None :
5752 pg_pool = ConnectionPool (
58- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
53+ dsn = dsn ,
5954 conn_recycling_method = conn_recycling_method ,
6055 )
6156
6257 conn = await pg_pool .connection ()
6358 await conn .execute ("SELECT 1" )
6459
6560
66- async def test_build_pool_failure () -> None :
61+ async def test_build_pool_failure (dsn : str ) -> None :
6762 with pytest .raises (expected_exception = ConnectionPoolConfigurationError ):
68- ConnectionPool (
69- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
70- connect_timeout_nanosec = 12 ,
71- )
63+ ConnectionPool (dsn = dsn , connect_timeout_nanosec = 12 )
64+
7265 with pytest .raises (expected_exception = ConnectionPoolConfigurationError ):
73- ConnectionPool (
74- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
75- connect_timeout_nanosec = 12 ,
76- )
66+ ConnectionPool (dsn = dsn , connect_timeout_nanosec = 12 )
67+
7768 with pytest .raises (expected_exception = ConnectionPoolConfigurationError ):
78- ConnectionPool (
79- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
80- keepalives_idle_nanosec = 12 ,
81- )
69+ ConnectionPool (dsn = dsn , keepalives_idle_nanosec = 12 )
70+
8271 with pytest .raises (expected_exception = ConnectionPoolConfigurationError ):
83- ConnectionPool (
84- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
85- keepalives_interval_nanosec = 12 ,
86- )
72+ ConnectionPool (dsn = dsn , keepalives_interval_nanosec = 12 )
8773
8874
8975@pytest .mark .parametrize (
@@ -96,12 +82,18 @@ async def test_build_pool_failure() -> None:
9682)
9783async def test_pool_target_session_attrs (
9884 target_session_attrs : TargetSessionAttrs ,
85+ postgres_host : str ,
86+ postgres_user : str ,
87+ postgres_password : str ,
88+ postgres_port : int ,
89+ postgres_dbname : str ,
9990) -> None :
10091 pg_pool = ConnectionPool (
101- db_name = "psqlpy_test" ,
102- host = "localhost" ,
103- username = "postgres" ,
104- password = "postgres" , # noqa: S106
92+ db_name = postgres_dbname ,
93+ host = postgres_host ,
94+ port = postgres_port ,
95+ username = postgres_user ,
96+ password = postgres_password ,
10597 target_session_attrs = target_session_attrs ,
10698 )
10799
@@ -122,21 +114,17 @@ async def test_pool_target_session_attrs(
122114)
123115async def test_pool_load_balance_hosts (
124116 load_balance_hosts : LoadBalanceHosts ,
117+ dsn : str ,
125118) -> None :
126- pg_pool = ConnectionPool (
127- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
128- load_balance_hosts = load_balance_hosts ,
129- )
119+ pg_pool = ConnectionPool (dsn = dsn , load_balance_hosts = load_balance_hosts )
130120
131121 conn = await pg_pool .connection ()
132122 await conn .execute ("SELECT 1" )
133123
134124
135- async def test_close_connection_pool () -> None :
125+ async def test_close_connection_pool (dsn : str ) -> None :
136126 """Test that `close` method closes connection pool."""
137- pg_pool = ConnectionPool (
138- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
139- )
127+ pg_pool = ConnectionPool (dsn = dsn )
140128
141129 conn = await pg_pool .connection ()
142130 await conn .execute ("SELECT 1" )
@@ -147,11 +135,9 @@ async def test_close_connection_pool() -> None:
147135 await pg_pool .connection ()
148136
149137
150- async def test_connection_pool_as_context_manager () -> None :
138+ async def test_connection_pool_as_context_manager (dsn : str ) -> None :
151139 """Test connection pool as context manager."""
152- with ConnectionPool (
153- dsn = "postgres://postgres:postgres@localhost:5432/psqlpy_test" ,
154- ) as pg_pool :
140+ with ConnectionPool (dsn = dsn ) as pg_pool :
155141 conn = await pg_pool .connection ()
156142 res = await conn .execute ("SELECT 1" )
157143 assert res .result ()
0 commit comments