@@ -39,8 +39,7 @@ async def test_transaction_init_parameters(
3939 deferrable : bool | None ,
4040 read_variant : ReadVariant | None ,
4141) -> None :
42- connection = await psql_pool .connection ()
43- async with connection .transaction (
42+ async with psql_pool .acquire () as connection , connection .transaction (
4443 isolation_level = isolation_level ,
4544 deferrable = deferrable ,
4645 read_variant = read_variant ,
@@ -79,6 +78,8 @@ async def test_transaction_begin(
7978
8079 assert len (result .result ()) == number_database_records
8180
81+ await transaction .commit ()
82+
8283
8384async def test_transaction_commit (
8485 psql_pool : ConnectionPool ,
@@ -97,15 +98,16 @@ async def test_transaction_commit(
9798
9899 # Make request from other connection, it mustn't know
99100 # about new INSERT data before commit.
100- result = await (await psql_pool .connection ()).execute (
101+ connection = await psql_pool .connection ()
102+ result = await connection .execute (
101103 f"SELECT * FROM { table_name } WHERE name = $1" ,
102104 parameters = [test_name ],
103105 )
104106 assert not result .result ()
105107
106108 await transaction .commit ()
107109
108- result = await ( await psql_pool . connection ()) .execute (
110+ result = await connection .execute (
109111 f"SELECT * FROM { table_name } WHERE name = $1" ,
110112 parameters = [test_name ],
111113 )
@@ -136,7 +138,8 @@ async def test_transaction_savepoint(
136138 assert result .result ()
137139
138140 await transaction .rollback_savepoint (savepoint_name = savepoint_name )
139- result = await (await psql_pool .connection ()).execute (
141+ connection = await psql_pool .connection ()
142+ result = await connection .execute (
140143 f"SELECT * FROM { table_name } WHERE name = $1" ,
141144 parameters = [test_name ],
142145 )
@@ -174,10 +177,12 @@ async def test_transaction_rollback(
174177 parameters = [test_name ],
175178 )
176179
177- result_from_conn = await (await psql_pool .connection ()).execute (
180+ connection = await psql_pool .connection ()
181+ result_from_conn = await connection .execute (
178182 f"INSERT INTO { table_name } VALUES ($1, $2)" ,
179183 parameters = [100 , test_name ],
180184 )
185+ connection .back_to_pool ()
181186
182187 assert not (result_from_conn .result ())
183188
@@ -344,14 +349,17 @@ async def test_transaction_send_underlying_connection_to_pool_manually(
344349
345350async def test_execute_batch_method (psql_pool : ConnectionPool ) -> None :
346351 """Test `execute_batch` method."""
347- await (await psql_pool .connection ()).execute (querystring = "DROP TABLE IF EXISTS execute_batch" )
348- await (await psql_pool .connection ()).execute (querystring = "DROP TABLE IF EXISTS execute_batch2" )
352+ connection = await psql_pool .connection ()
353+ await connection .execute (querystring = "DROP TABLE IF EXISTS execute_batch" )
354+ await connection .execute (querystring = "DROP TABLE IF EXISTS execute_batch2" )
349355 query = "CREATE TABLE execute_batch (name VARCHAR);CREATE TABLE execute_batch2 (name VARCHAR);"
350- async with psql_pool . acquire () as conn , conn .transaction () as transaction :
356+ async with connection .transaction () as transaction :
351357 await transaction .execute_batch (querystring = query )
352358 await transaction .execute (querystring = "SELECT * FROM execute_batch" )
353359 await transaction .execute (querystring = "SELECT * FROM execute_batch2" )
354360
361+ connection .back_to_pool ()
362+
355363
356364@pytest .mark .parametrize (
357365 "synchronous_commit" ,
0 commit comments