2020from google .api_core import exceptions
2121from google .cloud import kms
2222from google .cloud .storage ._helpers import _base64_md5hash
23+ from google .cloud .storage .retry import DEFAULT_RETRY
2324from . import _helpers
2425
2526
@@ -104,7 +105,11 @@ def shared_bucket_name():
104105def shared_bucket (storage_client , shared_bucket_name ):
105106 bucket = storage_client .bucket (shared_bucket_name )
106107 bucket .versioning_enabled = True
107- _helpers .retry_429_503 (bucket .create )()
108+ # Create the bucket only if it doesn't yet exist.
109+ try :
110+ storage_client .get_bucket (bucket )
111+ except exceptions .NotFound :
112+ _helpers .retry_429_503 (bucket .create )()
108113
109114 yield bucket
110115
@@ -119,11 +124,15 @@ def listable_bucket_name():
119124@pytest .fixture (scope = "session" )
120125def listable_bucket (storage_client , listable_bucket_name , file_data ):
121126 bucket = storage_client .bucket (listable_bucket_name )
122- _helpers .retry_429_503 (bucket .create )()
127+ # Create the bucket only if it doesn't yet exist.
128+ try :
129+ storage_client .get_bucket (bucket )
130+ except exceptions .NotFound :
131+ _helpers .retry_429_503 (bucket .create )()
123132
124133 info = file_data ["logo" ]
125134 source_blob = bucket .blob (_listable_filenames [0 ])
126- source_blob .upload_from_filename (info ["path" ])
135+ source_blob .upload_from_filename (info ["path" ], retry = DEFAULT_RETRY )
127136
128137 for filename in _listable_filenames [1 :]:
129138 _helpers .retry_bad_copy (bucket .copy_blob )(
@@ -159,7 +168,7 @@ def hierarchy_bucket(storage_client, hierarchy_bucket_name, file_data):
159168 simple_path = _file_data ["simple" ]["path" ]
160169 for filename in _hierarchy_filenames :
161170 blob = bucket .blob (filename )
162- blob .upload_from_filename (simple_path )
171+ blob .upload_from_filename (simple_path , retry = DEFAULT_RETRY )
163172
164173 yield bucket
165174
@@ -179,7 +188,12 @@ def signing_bucket_name():
179188@pytest .fixture (scope = "session" )
180189def signing_bucket (storage_client , signing_bucket_name ):
181190 bucket = storage_client .bucket (signing_bucket_name )
182- _helpers .retry_429_503 (bucket .create )()
191+ # Create the bucket only if it doesn't yet exist.
192+ try :
193+ storage_client .get_bucket (bucket )
194+ except exceptions .NotFound :
195+ _helpers .retry_429_503 (bucket .create )()
196+
183197 blob = bucket .blob ("README.txt" )
184198 blob .upload_from_string (_helpers .signing_blob_content )
185199
@@ -205,7 +219,11 @@ def default_ebh_bucket_name():
205219def default_ebh_bucket (storage_client , default_ebh_bucket_name ):
206220 bucket = storage_client .bucket (default_ebh_bucket_name )
207221 bucket .default_event_based_hold = True
208- _helpers .retry_429_503 (bucket .create )()
222+ # Create the bucket only if it doesn't yet exist.
223+ try :
224+ storage_client .get_bucket (bucket )
225+ except exceptions .NotFound :
226+ _helpers .retry_429_503 (bucket .create )()
209227
210228 yield bucket
211229
0 commit comments