Skip to content

Commit

Permalink
samples: fix flaky test teardown in servicedirectory (#7023)
Browse files Browse the repository at this point in the history
* samples: fix flaky test teardown in servicedirectory

* Improve logging

Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>

Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
  • Loading branch information
parthea and leahecole authored Nov 5, 2021
1 parent cc5e834 commit 4361f02
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions servicedirectory/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from google.api_core import exceptions
from google.cloud import servicedirectory_v1

import quickstart
import snippets

PROJECT_ID = environ['GOOGLE_CLOUD_PROJECT']
Expand All @@ -34,11 +35,16 @@
def teardown_module():
client = servicedirectory_v1.RegistrationServiceClient()
namespace_name = client.namespace_path(PROJECT_ID, LOCATION_ID, NAMESPACE_ID)
try:
namespace = client.get_namespace(name=namespace_name)
client.delete_namespace(name=namespace.name)
except exceptions.NotFound:
pass
all_namespaces = quickstart.list_namespaces(PROJECT_ID, LOCATION_ID).namespaces

# Delete namespace only if it exists
for namespace in all_namespaces:
if namespace_name in namespace.name:
try:
client.delete_namespace(name=namespace_name)
except exceptions.NotFound:
print("Namespace already deleted")
break


def test_create_namespace():
Expand Down

0 comments on commit 4361f02

Please sign in to comment.