@@ -109,22 +109,27 @@ def instance_id(self, admin_client, project_id, cluster_config):
109109 yield instance_id
110110 else :
111111 try :
112- operation = admin_client .instance_admin_client .create_instance (
113- parent = f"projects/{ project_id } " ,
114- instance_id = instance_id ,
115- instance = types .Instance (
116- display_name = "Test Instance" ,
117- # labels={"python-system-test": "true"},
118- ),
119- clusters = cluster_config ,
120- )
121- operation .result (timeout = 240 )
122- except exceptions .AlreadyExists :
123- pass
124- yield instance_id
125- admin_client .instance_admin_client .delete_instance (
126- name = f"projects/{ project_id } /instances/{ instance_id } "
127- )
112+ try :
113+ operation = admin_client .instance_admin_client .create_instance (
114+ parent = f"projects/{ project_id } " ,
115+ instance_id = instance_id ,
116+ instance = types .Instance (
117+ display_name = "Test Instance" ,
118+ # labels={"python-system-test": "true"},
119+ ),
120+ clusters = cluster_config ,
121+ )
122+ operation .result (timeout = 240 )
123+ except exceptions .AlreadyExists :
124+ pass
125+ yield instance_id
126+ finally :
127+ try :
128+ admin_client .instance_admin_client .delete_instance (
129+ name = f"projects/{ project_id } /instances/{ instance_id } "
130+ )
131+ except exceptions .NotFound :
132+ pass
128133
129134 @pytest .fixture (scope = "session" )
130135 def column_split_config (self ):
@@ -168,28 +173,30 @@ def table_id(
168173 retry = retry .Retry (
169174 predicate = retry .if_exception_type (exceptions .FailedPrecondition )
170175 )
176+ parent_path = f"projects/{ project_id } /instances/{ instance_id } "
171177 try :
172- parent_path = f"projects/{ project_id } /instances/{ instance_id } "
173- print (f"Creating table: { parent_path } /tables/{ init_table_id } " )
174- admin_client .table_admin_client .create_table (
175- request = {
176- "parent" : parent_path ,
177- "table_id" : init_table_id ,
178- "table" : {"column_families" : column_family_config },
179- "initial_splits" : [{"key" : key } for key in column_split_config ],
180- },
181- retry = retry ,
182- )
183- except exceptions .AlreadyExists :
184- pass
185- yield init_table_id
186- print (f"Deleting table: { parent_path } /tables/{ init_table_id } " )
187- try :
188- admin_client .table_admin_client .delete_table (
189- name = f"{ parent_path } /tables/{ init_table_id } "
190- )
191- except exceptions .NotFound :
192- print (f"Table { init_table_id } not found, skipping deletion" )
178+ try :
179+ print (f"Creating table: { parent_path } /tables/{ init_table_id } " )
180+ admin_client .table_admin_client .create_table (
181+ request = {
182+ "parent" : parent_path ,
183+ "table_id" : init_table_id ,
184+ "table" : {"column_families" : column_family_config },
185+ "initial_splits" : [{"key" : key } for key in column_split_config ],
186+ },
187+ retry = retry ,
188+ )
189+ except exceptions .AlreadyExists :
190+ pass
191+ yield init_table_id
192+ finally :
193+ print (f"Deleting table: { parent_path } /tables/{ init_table_id } " )
194+ try :
195+ admin_client .table_admin_client .delete_table (
196+ name = f"{ parent_path } /tables/{ init_table_id } "
197+ )
198+ except exceptions .NotFound :
199+ print (f"Table { init_table_id } not found, skipping deletion" )
193200
194201 @pytest .fixture (scope = "session" )
195202 def authorized_view_id (
@@ -217,36 +224,38 @@ def authorized_view_id(
217224 parent_path = f"projects/{ project_id } /instances/{ instance_id } /tables/{ table_id } "
218225 new_path = f"{ parent_path } /authorizedViews/{ new_view_id } "
219226 try :
220- print (f"Creating view: { new_path } " )
221- admin_client .table_admin_client .create_authorized_view (
222- request = {
223- "parent" : parent_path ,
224- "authorized_view_id" : new_view_id ,
225- "authorized_view" : {
226- "subset_view" : {
227- "row_prefixes" : [ALLOW_ALL ],
228- "family_subsets" : {
229- TEST_FAMILY : ALL_QUALIFIERS ,
230- TEST_FAMILY_2 : ALL_QUALIFIERS ,
231- TEST_AGGREGATE_FAMILY : ALL_QUALIFIERS ,
227+ try :
228+ print (f"Creating view: { new_path } " )
229+ admin_client .table_admin_client .create_authorized_view (
230+ request = {
231+ "parent" : parent_path ,
232+ "authorized_view_id" : new_view_id ,
233+ "authorized_view" : {
234+ "subset_view" : {
235+ "row_prefixes" : [ALLOW_ALL ],
236+ "family_subsets" : {
237+ TEST_FAMILY : ALL_QUALIFIERS ,
238+ TEST_FAMILY_2 : ALL_QUALIFIERS ,
239+ TEST_AGGREGATE_FAMILY : ALL_QUALIFIERS ,
240+ },
232241 },
233242 },
234243 },
235- } ,
236- retry = retry ,
237- )
238- except exceptions . AlreadyExists :
239- pass
240- except exceptions . MethodNotImplemented :
241- # will occur when run in emulator. Pass empty id
242- new_view_id = None
243- yield new_view_id
244- if new_view_id :
245- print (f"Deleting view: { new_path } " )
246- try :
247- admin_client .table_admin_client .delete_authorized_view (name = new_path )
248- except exceptions .NotFound :
249- print (f"View { new_view_id } not found, skipping deletion" )
244+ retry = retry ,
245+ )
246+ except exceptions . AlreadyExists :
247+ pass
248+ except exceptions . MethodNotImplemented :
249+ # will occur when run in emulator. Pass empty id
250+ new_view_id = None
251+ yield new_view_id
252+ finally :
253+ if new_view_id :
254+ print (f"Deleting view: { new_path } " )
255+ try :
256+ admin_client .table_admin_client .delete_authorized_view (name = new_path )
257+ except exceptions .NotFound :
258+ print (f"View { new_view_id } not found, skipping deletion" )
250259
251260 @pytest .fixture (scope = "session" )
252261 def project_id (self , client ):
0 commit comments