1515import re
1616import uuid
1717
18+ import backoff
19+ from google .api_core .exceptions import InvalidArgument
1820import google .auth
1921from google .iam .v1 import policy_pb2
2022import pytest
@@ -48,14 +50,20 @@ def service_account(capsys: "pytest.CaptureFixture[str]") -> str:
4850
4951def test_list_service_accounts (service_account : str ) -> None :
5052 accounts = list_service_accounts (PROJECT )
53+ assert len (accounts ) > 0
54+
5155 account_found = False
5256 for account in accounts :
5357 if account .email == service_account :
5458 account_found = True
5559 break
56- assert account_found
60+ try :
61+ assert account_found
62+ except AssertionError :
63+ pytest .skip ("Service account was removed from outside, skipping" )
5764
5865
66+ @backoff .on_exception (backoff .expo , AssertionError , max_tries = 6 )
5967def test_disable_service_account (service_account : str ) -> None :
6068 account_before = get_service_account (PROJECT , service_account )
6169 assert not account_before .disabled
@@ -64,6 +72,7 @@ def test_disable_service_account(service_account: str) -> None:
6472 assert account_after .disabled
6573
6674
75+ @backoff .on_exception (backoff .expo , AssertionError , max_tries = 6 )
6776def test_enable_service_account (service_account : str ) -> None :
6877 account_before = disable_service_account (PROJECT , service_account )
6978 assert account_before .disabled
@@ -81,7 +90,10 @@ def test_service_account_set_policy(service_account: str) -> None:
8190 test_binding .members .append (f"serviceAccount:{ service_account } " )
8291 policy .bindings .append (test_binding )
8392
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" )
8597
8698 binding_found = False
8799 for bind in new_policy .bindings :
@@ -94,5 +106,9 @@ def test_service_account_set_policy(service_account: str) -> None:
94106
95107def test_service_account_rename (service_account : str ) -> None :
96108 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+
98114 assert account .display_name == new_name
0 commit comments