@@ -648,7 +648,7 @@ async def test_token_cache_expiry_forces_reauthentication(
648648
649649 with patch ("time.time" , return_value = fixed_time ):
650650 # First connection should cache token
651- async with aconnect (
651+ async with await connect (
652652 database = db_name ,
653653 engine_name = engine_name ,
654654 auth = auth ,
@@ -661,7 +661,7 @@ async def test_token_cache_expiry_forces_reauthentication(
661661
662662 # Simulate time passing within token validity
663663 with patch ("time.time" , return_value = fixed_time + 1800 ): # 30 minutes later
664- async with aconnect (
664+ async with await connect (
665665 database = db_name ,
666666 engine_name = engine_name ,
667667 auth = auth ,
@@ -678,7 +678,7 @@ async def test_token_cache_expiry_forces_reauthentication(
678678 auth ._token = None
679679 auth ._expires = fixed_time # Set to expired time
680680
681- async with aconnect (
681+ async with await connect (
682682 database = db_name ,
683683 engine_name = engine_name ,
684684 auth = auth ,
@@ -791,7 +791,7 @@ def system_engine_callback_counter(request, **kwargs):
791791 )
792792
793793 # Connect with first credentials
794- async with connect (
794+ async with await connect (
795795 database = db_name ,
796796 engine_name = engine_name ,
797797 auth = auth1 ,
@@ -804,7 +804,7 @@ def system_engine_callback_counter(request, **kwargs):
804804 first_call_count = system_engine_call_counter
805805
806806 # Connect with second credentials
807- async with connect (
807+ async with await connect (
808808 database = db_name ,
809809 engine_name = engine_name ,
810810 auth = auth2 ,
@@ -817,7 +817,7 @@ def system_engine_callback_counter(request, **kwargs):
817817 second_call_count = system_engine_call_counter
818818
819819 # Connect again with first credentials
820- async with connect (
820+ async with await connect (
821821 database = db_name ,
822822 engine_name = engine_name ,
823823 auth = auth1 ,
@@ -1068,7 +1068,7 @@ def system_engine_callback_counter(request, **kwargs):
10681068 )
10691069
10701070 # Connect to first account
1071- async with connect (
1071+ async with await connect (
10721072 database = db_name ,
10731073 engine_name = engine_name ,
10741074 auth = auth ,
@@ -1080,7 +1080,7 @@ def system_engine_callback_counter(request, **kwargs):
10801080 first_account_calls = system_engine_call_counter
10811081
10821082 # Connect to second account with same credentials
1083- async with connect (
1083+ async with await connect (
10841084 database = db_name ,
10851085 engine_name = engine_name ,
10861086 auth = auth ,
@@ -1092,7 +1092,7 @@ def system_engine_callback_counter(request, **kwargs):
10921092 second_account_calls = system_engine_call_counter
10931093
10941094 # Connect again to first account
1095- async with connect (
1095+ async with await connect (
10961096 database = db_name ,
10971097 engine_name = engine_name ,
10981098 auth = auth ,
@@ -1117,7 +1117,6 @@ def system_engine_callback_counter(request, **kwargs):
11171117
11181118async def test_database_switching_with_same_engine (
11191119 db_name : str ,
1120- second_db_name : str ,
11211120 engine_name : str ,
11221121 auth_url : str ,
11231122 httpx_mock : HTTPXMock ,
@@ -1126,18 +1125,20 @@ async def test_database_switching_with_same_engine(
11261125 get_system_engine_callback : Callable ,
11271126 system_engine_query_url : str ,
11281127 system_engine_no_db_query_url : str ,
1129- use_db_callback : Callable ,
1130- use_engine_callback : Callable ,
11311128 query_callback : Callable ,
11321129 query_url : str ,
11331130 auth : Auth ,
11341131 account_name : str ,
11351132 api_endpoint : str ,
1133+ use_engine_callback : Callable ,
1134+ dynamic_use_database_callback : Callable ,
11361135):
11371136 """
11381137 Test that we can switch between different databases using the same engine
11391138 while maintaining proper database context for each cursor.
11401139 """
1140+ second_db_name = f"{ db_name } _second"
1141+
11411142 # Mock HTTP calls
11421143 httpx_mock .add_callback (check_credentials_callback , url = auth_url , is_reusable = True )
11431144 httpx_mock .add_callback (
@@ -1146,6 +1147,9 @@ async def test_database_switching_with_same_engine(
11461147 is_reusable = True ,
11471148 )
11481149
1150+ # Create dynamic callback for both databases
1151+ use_db_callback = dynamic_use_database_callback (db_name , second_db_name )
1152+
11491153 # Add USE DATABASE callbacks for both databases
11501154 httpx_mock .add_callback (
11511155 use_db_callback ,
0 commit comments