Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit ed7cbba

Browse files
authored
test: harden pytest fixture setup stage (#1323)
* test: update pytest fixtures bucket creation * apply default retry to fixture uploads
1 parent 152b249 commit ed7cbba

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

tests/system/conftest.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from google.api_core import exceptions
2121
from google.cloud import kms
2222
from google.cloud.storage._helpers import _base64_md5hash
23+
from google.cloud.storage.retry import DEFAULT_RETRY
2324
from . import _helpers
2425

2526

@@ -104,7 +105,11 @@ def shared_bucket_name():
104105
def 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")
120125
def 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")
180189
def 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():
205219
def 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

Comments
 (0)