@@ -14,26 +14,32 @@ async def _test_isolation_level_read_only(
1414 isolation_level : str ,
1515 read_only : bool ,
1616 ):
17- await connection .cursor ().execute (
18- "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
19- )
20- connection .set_isolation_level (isolation_level )
17+ async with connection .cursor () as cursor :
18+ with suppress (dbapi .DatabaseError ):
19+ await cursor .execute ("DROP TABLE foo" )
2120
22- cursor = connection .cursor ()
21+ async with connection .cursor () as cursor :
22+ await cursor .execute (
23+ "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
24+ )
25+
26+ connection .set_isolation_level (isolation_level )
2327
2428 await connection .begin ()
2529
26- query = "UPSERT INTO foo(id) VALUES (1)"
27- if read_only :
28- with pytest .raises (dbapi .DatabaseError ):
30+ async with connection .cursor () as cursor :
31+ query = "UPSERT INTO foo(id) VALUES (1)"
32+ if read_only :
33+ with pytest .raises (dbapi .DatabaseError ):
34+ await cursor .execute (query )
35+ await cursor .finish_query ()
36+ else :
2937 await cursor .execute (query )
30- else :
31- await cursor .execute (query )
3238
3339 await connection .rollback ()
3440
35- await connection .cursor (). execute ( "DROP TABLE foo" )
36- await connection . cursor (). close ( )
41+ async with connection .cursor () as cursor :
42+ cursor . execute ( "DROP TABLE foo" )
3743
3844 async def _test_connection (self , connection : dbapi .Connection ):
3945 await connection .commit ()
@@ -42,6 +48,7 @@ async def _test_connection(self, connection: dbapi.Connection):
4248 cur = connection .cursor ()
4349 with suppress (dbapi .DatabaseError ):
4450 await cur .execute ("DROP TABLE foo" )
51+ await cur .finish_query ()
4552
4653 assert not await connection .check_exists ("/local/foo" )
4754 with pytest .raises (dbapi .ProgrammingError ):
@@ -50,6 +57,7 @@ async def _test_connection(self, connection: dbapi.Connection):
5057 await cur .execute (
5158 "CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
5259 )
60+ await cur .finish_query ()
5361
5462 assert await connection .check_exists ("/local/foo" )
5563
@@ -66,10 +74,12 @@ async def _test_cursor_raw_query(self, connection: dbapi.Connection):
6674
6775 with suppress (dbapi .DatabaseError ):
6876 await cur .execute ("DROP TABLE test" )
77+ await cur .finish_query ()
6978
7079 await cur .execute (
7180 "CREATE TABLE test(id Int64 NOT NULL, text Utf8, PRIMARY KEY (id))"
7281 )
82+ await cur .finish_query ()
7383
7484 await cur .execute (
7585 """
@@ -91,6 +101,7 @@ async def _test_cursor_raw_query(self, connection: dbapi.Connection):
91101 )
92102 },
93103 )
104+ await cur .finish_query ()
94105
95106 await cur .execute ("DROP TABLE test" )
96107
@@ -104,6 +115,7 @@ async def _test_errors(self, connection: dbapi.Connection):
104115
105116 with suppress (dbapi .DatabaseError ):
106117 await cur .execute ("DROP TABLE test" )
118+ await cur .finish_query ()
107119
108120 with pytest .raises (dbapi .DataError ):
109121 await cur .execute ("SELECT 18446744073709551616" )
@@ -118,8 +130,11 @@ async def _test_errors(self, connection: dbapi.Connection):
118130 await cur .execute ("SELECT * FROM test" )
119131
120132 await cur .execute ("CREATE TABLE test(id Int64, PRIMARY KEY (id))" )
133+ await cur .finish_query ()
121134
122135 await cur .execute ("INSERT INTO test(id) VALUES(1)" )
136+ await cur .finish_query ()
137+
123138 with pytest .raises (dbapi .IntegrityError ):
124139 await cur .execute ("INSERT INTO test(id) VALUES(1)" )
125140
@@ -143,10 +158,10 @@ async def connection(self, endpoint, database):
143158 [
144159 (dbapi .IsolationLevel .SERIALIZABLE , False ),
145160 (dbapi .IsolationLevel .AUTOCOMMIT , False ),
146- # (dbapi.IsolationLevel.ONLINE_READONLY, True),
147- # (dbapi.IsolationLevel.ONLINE_READONLY_INCONSISTENT, True),
148- # (dbapi.IsolationLevel.STALE_READONLY, True),
149- # (dbapi.IsolationLevel.SNAPSHOT_READONLY, True),
161+ (dbapi .IsolationLevel .ONLINE_READONLY , True ),
162+ (dbapi .IsolationLevel .ONLINE_READONLY_INCONSISTENT , True ),
163+ (dbapi .IsolationLevel .STALE_READONLY , True ),
164+ (dbapi .IsolationLevel .SNAPSHOT_READONLY , True ),
150165 ],
151166 )
152167 async def test_isolation_level_read_only (
0 commit comments