tests: try multiple times to get a database name (#42634)

This commit is contained in:
Thomas NOËL 2020-05-07 17:22:56 +02:00 committed by Frédéric Péters
parent 84c72bd320
commit 7e07d08a67
1 changed files with 11 additions and 2 deletions

View File

@ -47,8 +47,17 @@ def cursor():
@pytest.fixture
def database(cursor):
dbname = 'wcstests%d' % random.randint(0, 100000)
cursor.execute('CREATE DATABASE %s' % dbname)
i = 0
while True:
dbname = 'wcstests%d' % random.randint(0, 100000)
try:
cursor.execute('CREATE DATABASE %s' % dbname)
break
except psycopg2.Error:
if i < 5:
i += 1
continue
raise
yield dbname
cleanup_connection()
cursor.execute('DROP DATABASE %s' % dbname)