Changeset - c20abcf4adb9
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 8 years ago 2017-07-05 21:08:17
thomas.de.schampheleire@gmail.com
tests: fix failures due to environment LANG settings (Issue #286)

When the environment in which the tests are run dictates a non-English
language (e.g. via LANG=de_DE.UTF-8), certain tests started to fail because
formencode validation messages where translated in that language.

A test failing this way is for example
test_create_in_group_without_needed_permissions in
kallithea/tests/functional/test_admin_repos.py .

This is a regression of commit 3b29103657df (i18n: remove explicit
formencode language setting), but in fact reverting it is not the right
solution as there is no problem except during test execution.

Instead, force the formencode language to 'empty' (meaning English) for test
execution only.

See also http://www.formencode.org/en/latest/i18n.html
1 file changed with 3 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/conftest.py
Show inline comments
 
import os
 
import sys
 
import logging
 
import pkg_resources
 
import time
 

	
 
import formencode
 
from paste.deploy import loadwsgi
 
from routes.util import URLGenerator
 
import pytest
 
from pytest_localserver.http import WSGIServer
 

	
 
from kallithea.controllers.root import RootController
 
from kallithea.lib.utils import repo2db_mapper
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.model.db import Setting, User, UserIpMap
 
from kallithea.model.scm import ScmModel
 
from kallithea.tests.base import invalidate_all_caches, TEST_USER_REGULAR_LOGIN, TESTS_TMP_PATH, \
 
@@ -48,24 +49,26 @@ def pytest_configure():
 
    # set KALLITHEA_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests
 
    if not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0)):
 
        create_test_index(TESTS_TMP_PATH, context.config(), True)
 

	
 
    kallithea.tests.base.testapp = context.create()
 
    # do initial repo scan
 
    repo2db_mapper(ScmModel().repo_scan(TESTS_TMP_PATH))
 

	
 
    logging.disable(logging.NOTSET)
 

	
 
    kallithea.tests.base.url = URLGenerator(RootController().mapper, {'HTTP_HOST': 'example.com'})
 

	
 
    # set fixed language for form messages, regardless of environment settings
 
    formencode.api.set_stdtranslation(languages=[])
 

	
 
@pytest.fixture
 
def create_test_user():
 
    """Provide users that automatically disappear after test is over."""
 
    test_user_ids = []
 
    def _create_test_user(user_form):
 
        user = UserModel().create(user_form)
 
        test_user_ids.append(user.user_id)
 
        return user
 
    yield _create_test_user
 
    for user_id in test_user_ids:
 
        UserModel().delete(user_id)
0 comments (0 inline, 0 general)