# HG changeset patch # User domruf # Date 1502742868 -7200 # Node ID cddff7f0dd088d999d888f6269bee5860d4c41fa # Parent dfb31968225dd7e81f2ff80f746a3aa9a4cd60b4 tests: use temporary copy of test.ini, possibly customized for TEST_DB It was an undocumented feature that if setting the environment variable TEST_DB, that would be used for tests instead of the default kallithea/tests/test.ini sqlalchemy.url . That did however not work for Git hooks and tests would fail. Instead, create a copy of test.ini in the temp folder and use that for testing. If TEST_DB is set, edit the file so the specified DB URL is used. This fixes Git hook related tests if TEST_DB is used. Since this also changes the path of %(here)s to the temporary location, just use the default paths. This also has the advantage that the data folders are now in the temp folder as well. Therefore a broken data folder, from a past run, can no longer influence a test. diff -r dfb31968225d -r cddff7f0dd08 kallithea/tests/conftest.py --- a/kallithea/tests/conftest.py Sun Jul 30 14:26:10 2017 +0200 +++ b/kallithea/tests/conftest.py Mon Aug 14 22:34:28 2017 +0200 @@ -1,4 +1,5 @@ import os +import re import sys import logging import pkg_resources @@ -34,12 +35,20 @@ # Disable INFO logging of test database creation, restore with NOTSET logging.disable(logging.INFO) - context = loadwsgi.loadcontext(loadwsgi.APP, 'config:kallithea/tests/test.ini', relative_to=path) + with open(os.path.join(path, 'kallithea/tests/test.ini'), 'r') as input_file: + test_ini = input_file.read() if os.environ.get('TEST_DB'): - # swap config if we pass environment variable - context.local_conf['sqlalchemy.url'] = os.environ.get('TEST_DB') + test_ini = re.sub('^\s*sqlalchemy.url\s*=.*$', + 'sqlalchemy.url = %s' % os.environ.get('TEST_DB'), + test_ini, + flags=re.M) + test_ini_file = os.path.join(TESTS_TMP_PATH, 'test.ini') + with open(test_ini_file, 'w') as output_file: + output_file.write(test_ini) + + context = loadwsgi.loadcontext(loadwsgi.APP, 'config:%s' % test_ini_file) from kallithea.tests.fixture import create_test_env, create_test_index # set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and test repos diff -r dfb31968225d -r cddff7f0dd08 kallithea/tests/test.ini --- a/kallithea/tests/test.ini Sun Jul 30 14:26:10 2017 +0200 +++ b/kallithea/tests/test.ini Mon Aug 14 22:34:28 2017 +0200 @@ -184,18 +184,15 @@ ## Fallback language, empty for English (valid values are the names of subdirectories in kallithea/i18n): i18n.lang = -#cache_dir = %(here)s/data -cache_dir = %(here)s/../../data/test/cache -#index_dir = %(here)s/data/index -index_dir = %(here)s/../../data/test/index +cache_dir = %(here)s/data +index_dir = %(here)s/data/index ## perform a full repository scan on each server start, this should be ## set to false after first startup, to allow faster server restarts. initial_repo_scan = false ## uncomment and set this path to use archive download cache -#archive_cache_dir = %(here)s/tarballcache -archive_cache_dir = %(here)s/../../data/test/tarballcache +archive_cache_dir = %(here)s/tarballcache ## change this to unique ID for security app_instance_uuid = test @@ -343,10 +340,8 @@ ### BEAKER CACHE #### #################################### -#beaker.cache.data_dir = %(here)s/data/cache/data -beaker.cache.data_dir = %(here)s/../../data/test/cache/data -#beaker.cache.lock_dir = %(here)s/data/cache/lock -beaker.cache.lock_dir = %(here)s/../../data/test/cache/lock +beaker.cache.data_dir = %(here)s/data/cache/data +beaker.cache.lock_dir = %(here)s/data/cache/lock beaker.cache.regions = short_term,long_term,sql_cache_short @@ -499,8 +494,7 @@ ######################################################### # SQLITE [default] -#sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60 -sqlalchemy.url = sqlite:///%(here)s/kallithea_test.sqlite +sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60 # POSTGRESQL #sqlalchemy.url = postgresql://user:pass@localhost/kallithea diff -r dfb31968225d -r cddff7f0dd08 scripts/generate-ini.py --- a/scripts/generate-ini.py Sun Jul 30 14:26:10 2017 +0200 +++ b/scripts/generate-ini.py Mon Aug 14 22:34:28 2017 +0200 @@ -41,12 +41,6 @@ 'show_revision_number': 'true', 'beaker.cache.sql_cache_short.expire': '1', 'beaker.session.secret': '{74e0cd75-b339-478b-b129-07dd221def1f}', - 'cache_dir': '%(here)s/../../data/test/cache', - 'index_dir': '%(here)s/../../data/test/index', - 'archive_cache_dir': '%(here)s/../../data/test/tarballcache', - 'beaker.cache.data_dir': '%(here)s/../../data/test/cache/data', - 'beaker.cache.lock_dir': '%(here)s/../../data/test/cache/lock', - 'sqlalchemy.url': 'sqlite:///%(here)s/kallithea_test.sqlite', }, '[handler_console]': { 'level': 'DEBUG',