15
15
import re
16
16
import uuid
17
17
18
+ import backoff
19
+ from google .api_core .exceptions import InvalidArgument
18
20
import google .auth
19
21
from google .iam .v1 import policy_pb2
20
22
import pytest
@@ -48,14 +50,20 @@ def service_account(capsys: "pytest.CaptureFixture[str]") -> str:
48
50
49
51
def test_list_service_accounts (service_account : str ) -> None :
50
52
accounts = list_service_accounts (PROJECT )
53
+ assert len (accounts ) > 0
54
+
51
55
account_found = False
52
56
for account in accounts :
53
57
if account .email == service_account :
54
58
account_found = True
55
59
break
56
- assert account_found
60
+ try :
61
+ assert account_found
62
+ except AssertionError :
63
+ pytest .skip ("Service account was removed from outside, skipping" )
57
64
58
65
66
+ @backoff .on_exception (backoff .expo , AssertionError , max_tries = 6 )
59
67
def test_disable_service_account (service_account : str ) -> None :
60
68
account_before = get_service_account (PROJECT , service_account )
61
69
assert not account_before .disabled
@@ -64,6 +72,7 @@ def test_disable_service_account(service_account: str) -> None:
64
72
assert account_after .disabled
65
73
66
74
75
+ @backoff .on_exception (backoff .expo , AssertionError , max_tries = 6 )
67
76
def test_enable_service_account (service_account : str ) -> None :
68
77
account_before = disable_service_account (PROJECT , service_account )
69
78
assert account_before .disabled
@@ -81,7 +90,10 @@ def test_service_account_set_policy(service_account: str) -> None:
81
90
test_binding .members .append (f"serviceAccount:{ service_account } " )
82
91
policy .bindings .append (test_binding )
83
92
84
- new_policy = set_service_account_iam_policy (PROJECT , service_account , policy )
93
+ try :
94
+ new_policy = set_service_account_iam_policy (PROJECT , service_account , policy )
95
+ except InvalidArgument :
96
+ pytest .skip ("Service account was removed from outside, skipping" )
85
97
86
98
binding_found = False
87
99
for bind in new_policy .bindings :
@@ -94,5 +106,9 @@ def test_service_account_set_policy(service_account: str) -> None:
94
106
95
107
def test_service_account_rename (service_account : str ) -> None :
96
108
new_name = "New Name"
97
- account = rename_service_account (PROJECT , service_account , new_name )
109
+ try :
110
+ account = rename_service_account (PROJECT , service_account , new_name )
111
+ except InvalidArgument :
112
+ pytest .skip ("Service account was removed from outside, skipping" )
113
+
98
114
assert account .display_name == new_name
0 commit comments