Projet

Général

Profil

0001-tox-fixed-inconsistent-obscure-db-names-during-tests.patch

A. Berriot, 04 août 2022 09:31

Télécharger (1,63 ko)

Voir les différences:

Subject: [PATCH] tox: fixed inconsistent / obscure db names during tests
 (#67933)

 hobo/test_utils.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
hobo/test_utils.py
6 6
    """
7 7
    PostgreSQL database name limit is 68 characters, which can become
8 8
    an issue during testing, because we need to build a unique
9
    database name using the branch and tox env.
9
    database name using the branch and prefix.
10

  
11
    Also, when running tests in parallel through `tox -p`,
12
    pytest django append the tox env name automatically
13
    through a fixture.
10 14

  
11 15
    Ergo, the following code to ensure the database name is always shorter than 68
12 16
    characters.
13 17
    """
14
    BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')
15
    TOX_ENV_NAME = os.environ.get('TOX_ENV_NAME')
16
    DB_NAME = '_'.join([part for part in [prefix, BRANCH_NAME, TOX_ENV_NAME] if part])
17
    DB_NAME = hashlib.sha256(DB_NAME.encode()).hexdigest()[:10]
18

  
19
    return DB_NAME
18
    BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')[:15]
19
    parts = [prefix, BRANCH_NAME]
20
    if not os.environ.get("TOX_PARALLEL_ENV"):
21
        # when we're in parallel mode, pytest-django will do this
22
        # for us at a later point
23
        parts.append(os.environ.get('TOX_ENV_NAME'))
24
    return '_'.join(parts)
20
-