diff --git a/openstackclient/tests/functional/identity/v2/common.py b/openstackclient/tests/functional/identity/v2/common.py
index ad02f7791b..4f3e180134 100644
--- a/openstackclient/tests/functional/identity/v2/common.py
+++ b/openstackclient/tests/functional/identity/v2/common.py
@@ -43,8 +43,8 @@ class IdentityTests(base.TestCase):
         # prepare v2 env
         os.environ['OS_IDENTITY_API_VERSION'] = '2.0'
         auth_url = os.environ.get('OS_AUTH_URL')
-        auth_url = auth_url.replace('v3', 'v2.0')
-        os.environ['OS_AUTH_URL'] = auth_url
+        if auth_url:
+            os.environ['OS_AUTH_URL'] = auth_url.replace('v3', 'v2.0')
 
         # create dummy project
         cls.project_name = data_utils.rand_name('TestProject')
diff --git a/openstackclient/tests/functional/identity/v3/common.py b/openstackclient/tests/functional/identity/v3/common.py
index a509574cb7..1ec3ac9281 100644
--- a/openstackclient/tests/functional/identity/v3/common.py
+++ b/openstackclient/tests/functional/identity/v3/common.py
@@ -56,8 +56,8 @@ class IdentityTests(base.TestCase):
         # prepare v3 env
         os.environ['OS_IDENTITY_API_VERSION'] = '3'
         auth_url = os.environ.get('OS_AUTH_URL')
-        auth_url = auth_url.replace('v2.0', 'v3')
-        os.environ['OS_AUTH_URL'] = auth_url
+        if auth_url:
+            os.environ['OS_AUTH_URL'] = auth_url.replace('v2.0', 'v3')
 
         # create dummy domain
         cls.domain_name = data_utils.rand_name('TestDomain')