33
33
import pytest
34
34
35
35
from test_utils .system import unique_resource_id
36
+ from google .api_core .exceptions import NotFound
36
37
from google .cloud ._helpers import UTC
37
38
from google .cloud .bigtable import Client
38
39
from google .cloud .bigtable import enums
39
40
40
41
41
- INSTANCE_ID = "snippet-" + unique_resource_id ("-" )
42
+ INSTANCE_ID = "snippet-tests " + unique_resource_id ("-" )
42
43
CLUSTER_ID = "clus-1-" + unique_resource_id ("-" )
43
44
LOCATION_ID = "us-central1-f"
44
45
ALT_LOCATION_ID = "us-central1-a"
52
53
.strftime ("%Y-%m-%dt%H-%M-%S" )
53
54
)
54
55
LABELS = {LABEL_KEY : str (LABEL_STAMP )}
56
+ INSTANCES_TO_DELETE = []
55
57
56
58
57
59
class Config (object ):
@@ -79,10 +81,15 @@ def setup_module():
79
81
operation = Config .INSTANCE .create (clusters = [cluster ])
80
82
# We want to make sure the operation completes.
81
83
operation .result (timeout = 100 )
84
+ INSTANCES_TO_DELETE .append (Config .INSTANCE )
82
85
83
86
84
87
def teardown_module ():
85
- Config .INSTANCE .delete ()
88
+ for instance in INSTANCES_TO_DELETE :
89
+ try :
90
+ instance .delete ()
91
+ except NotFound :
92
+ pass
86
93
87
94
88
95
def test_bigtable_create_instance ():
@@ -107,9 +114,14 @@ def test_bigtable_create_instance():
107
114
default_storage_type = storage_type ,
108
115
)
109
116
operation = instance .create (clusters = [cluster ])
117
+
118
+ # Make sure this instance gets deleted after the test case.
119
+ INSTANCES_TO_DELETE .append (instance )
120
+
110
121
# We want to make sure the operation completes.
111
122
operation .result (timeout = 100 )
112
123
# [END bigtable_create_prod_instance]
124
+
113
125
assert instance .exists ()
114
126
instance .delete ()
115
127
@@ -281,6 +293,9 @@ def test_bigtable_update_instance():
281
293
# [END bigtable_update_instance]
282
294
assert instance .display_name == display_name
283
295
296
+ # Make sure this instance gets deleted after the test case.
297
+ INSTANCES_TO_DELETE .append (instance )
298
+
284
299
285
300
def test_bigtable_update_cluster ():
286
301
# [START bigtable_update_cluster]
@@ -367,6 +382,10 @@ def test_bigtable_delete_instance():
367
382
default_storage_type = STORAGE_TYPE ,
368
383
)
369
384
operation = instance .create (clusters = [cluster ])
385
+
386
+ # Make sure this instance gets deleted after the test case.
387
+ INSTANCES_TO_DELETE .append (instance )
388
+
370
389
# We want to make sure the operation completes.
371
390
operation .result (timeout = 100 )
372
391
0 commit comments