Skip to content

Commit 561635f

Browse files
authored
fix(iam.deny): Skipping test if we don't have permission to run it. (#11717)
* fix(iam.deny): Skipping test if we don't have permission to run it. * Fixing lint
1 parent 4eef230 commit 561635f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

iam/cloud-client/snippets/conftest.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
import uuid
1818

19+
from google.api_core.exceptions import PermissionDenied
1920
import google.auth
2021
from google.cloud import iam_v2
2122
from google.cloud.iam_admin_v1 import IAMClient, ListRolesRequest
@@ -34,12 +35,14 @@
3435
@pytest.fixture
3536
def deny_policy(capsys: "pytest.CaptureFixture[str]") -> None:
3637
policy_id = f"test-deny-policy-{uuid.uuid4()}"
38+
try:
39+
# Delete any existing policies. Otherwise it might throw quota issue.
40+
delete_existing_deny_policies(PROJECT, "test-deny-policy")
3741

38-
# Delete any existing policies. Otherwise it might throw quota issue.
39-
delete_existing_deny_policies(PROJECT, "test-deny-policy")
40-
41-
# Create the Deny policy.
42-
create_deny_policy(PROJECT, policy_id)
42+
# Create the Deny policy.
43+
create_deny_policy(PROJECT, policy_id)
44+
except PermissionDenied:
45+
pytest.skip("Don't have permissions to run this test.")
4346

4447
yield policy_id
4548

0 commit comments

Comments
 (0)