File tree 1 file changed +15
-2
lines changed
bigquery-reservation/snippets
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 21
21
import pytest
22
22
23
23
24
+ @pytest .fixture (scope = "session" , autouse = True )
25
+ def cleanup_commitments (
26
+ reservation_client : reservation_service .ReservationServiceClient , location_path : str
27
+ ) -> None :
28
+ for commitment in reservation_client .list_capacity_commitments (
29
+ parent = location_path
30
+ ):
31
+ if commitment .state == reservation_types .CapacityCommitment .State .FAILED or (
32
+ commitment .commitment_start_time is not None
33
+ and commitment .commitment_start_time
34
+ < datetime .datetime .now (datetime .timezone .utc ) - datetime .timedelta (days = 1 )
35
+ ):
36
+ reservation_client .delete_capacity_commitment (name = commitment .name )
37
+
38
+
24
39
@pytest .fixture (scope = "session" )
25
40
def project_id () -> str :
26
41
return os .environ ["GOOGLE_CLOUD_PROJECT" ]
@@ -47,8 +62,6 @@ def location_path(project_id: str, location: str) -> str:
47
62
def capacity_commitment (
48
63
location_path : str , reservation_client : reservation_service .ReservationServiceClient
49
64
) -> reservation_types .CapacityCommitment :
50
- # TODO(b/196082966): If custom names or creation date property are added,
51
- # do pre-test cleanup of past commitments.
52
65
commitment = reservation_types .CapacityCommitment ()
53
66
commitment .slot_count = 100
54
67
commitment .plan = reservation_types .CapacityCommitment .CommitmentPlan .FLEX
You can’t perform that action at this time.
0 commit comments