hobo/hobo/test_utils.py

21 lines
734 B
Python

import os
def get_safe_db_name():
"""
PostgreSQL database name limit is 63 characters, which can become
an issue during testing, because we need to build a unique
database name using the branch name and tox env.
Also, when running tests in parallel through `tox -p`,
pytest django append the tox env name automatically
through a fixture so we have to skip this step.
"""
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')[:15]
parts = [BRANCH_NAME]
if not os.environ.get("TOX_PARALLEL_ENV"):
# when we're in parallel mode, pytest-django will do this
# for us at a later point
parts.append(os.environ.get('TOX_ENV_NAME'))
return '_'.join(parts)