@@ -96,7 +96,8 @@ def _docker_server() -> Optional[Any]:
96
96
print (f'Warning: Failed to stop Docker container: { e } ' )
97
97
98
98
99
- def get_connection_url (_docker_server : Optional [Any ] = None ) -> str :
99
+ @pytest .fixture (scope = 'session' )
100
+ def base_connection_url (_docker_server : Optional [Any ]) -> str :
100
101
"""
101
102
Get the SingleStoreDB connection URL from environment variable or Docker.
102
103
@@ -109,14 +110,9 @@ def get_connection_url(_docker_server: Optional[Any] = None) -> str:
109
110
str : Connection URL for SingleStoreDB
110
111
"""
111
112
# First check environment variable
112
- url = os .environ .get ('SINGLESTOREDB_URL' )
113
+ url = os .environ .get ('SINGLESTOREDB_URL' , '' ). strip ( )
113
114
if url :
114
- # Format the URL properly
115
- if url .startswith ('http://' ) or url .startswith ('https://' ):
116
- return 'singlestoredb+' + url
117
- elif not url .startswith ('singlestoredb://' ):
118
- return 'singlestoredb://' + url
119
- return url
115
+ return url .replace ('singlestoredb://' , '' ).replace ('singlestoredb+' , '' )
120
116
121
117
# If no env var, use Docker server if available
122
118
if _docker_server :
@@ -144,30 +140,17 @@ def generate_table_name_prefix() -> str:
144
140
return f'tbl_{ random_suffix } _'
145
141
146
142
147
- @pytest .fixture (scope = 'session' )
148
- def base_connection_url (_docker_server : Optional [Any ]) -> str :
149
- """Get the base connection URL without a specific database."""
150
- url = get_connection_url (_docker_server )
151
- # Remove any database name from the URL
152
- # if '://' in url:
153
- # if '/' in url.split('://', 1)[1]:
154
- # # Has a database specified
155
- # parts = url.split('/')
156
- # return '/'.join(parts[:-1])
157
- return url
158
-
159
-
160
143
@pytest .fixture (scope = 'session' )
161
144
def test_database (base_connection_url : str ) -> Generator [str , None , None ]:
162
145
"""Create a single test database for the entire test session."""
163
146
db_name = generate_test_db_name ()
164
147
165
- # Always use the standard connection URL for database creation
166
- if _docker_server_instance is not None :
167
- if 'http://' in base_connection_url or 'https://' in base_connection_url :
168
- base_connection_url = _docker_server_instance .connection_url
148
+ if base_connection_url .startswith ('http://' ) or \
149
+ base_connection_url .startswith ('https://' ):
150
+ base_connection_url = 'singlestoredb+' + base_connection_url
151
+ else :
152
+ base_connection_url = 'singlestoredb://' + base_connection_url
169
153
170
- # Connect without specifying a database
171
154
engine = create_engine (base_connection_url )
172
155
173
156
# Create the test database
@@ -194,6 +177,12 @@ def test_engine(
194
177
base_connection_url : str , test_database : str ,
195
178
) -> Generator [Engine , None , None ]:
196
179
"""Create a SQLAlchemy engine connected to the shared test database."""
180
+ if base_connection_url .startswith ('http://' ) or \
181
+ base_connection_url .startswith ('https://' ):
182
+ base_connection_url = 'singlestoredb+' + base_connection_url
183
+ else :
184
+ base_connection_url = 'singlestoredb://' + base_connection_url
185
+
197
186
# Create engine with the test database
198
187
test_url = f'{ base_connection_url } /{ test_database } '
199
188
engine = create_engine (test_url )
0 commit comments