Skip to content

Commit

Permalink
Generate unique random name
Browse files Browse the repository at this point in the history
Change-Id: I5f8fff33a3cd3d3a55c9c6678a25fd51d96913ea
Closes-Bug: 1735582
(cherry picked from commit 9a39849)
  • Loading branch information
Senthilnathan Murugappan committed Dec 5, 2017
1 parent b54577b commit 094d782
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tcutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ def get_random_name(prefix=None, constant_prefix='ctest'):
ret_val = '%s-%s' %(constant_prefix, ret_val)
return ret_val

def get_unique_random_name(*args, **kwargs):
if 'unique_random_name' not in env.keys():
env['unique_random_name'] = list()
while True:
name = get_random_name(*args, **kwargs)
if name not in env.unique_random_name:
env.unique_random_name.append(name)
return name

def gen_str_with_spl_char(size, char_set=None):
if char_set:
Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from common import log_orig as contrail_logging
#from common import config
import logging as std_logging
from tcutils.util import get_random_name
from tcutils.util import get_unique_random_name

def attr(*args, **kwargs):
"""A decorator which applies the testtools attr decorator
Expand Down Expand Up @@ -53,7 +53,7 @@ def id(self):
if tag in attributes:
return orig
# A hack to please testtools to get uniq testcase names
return get_random_name()
return get_unique_random_name()

class BaseTestCase(TagsHack,
testtools.testcase.WithAttributes,
Expand Down

0 comments on commit 094d782

Please sign in to comment.