From 7f994fc993f9fd49fdb1f060aa28f0a43f7c8a55 Mon Sep 17 00:00:00 2001 From: RhodeCode Admin Date: Mon, 11 Mar 2024 09:56:10 +0100 Subject: [PATCH] tests(core): made the test flag setting more flexible. We no longer use .ini setting, but relly on env variables, that is now set via pytest env plugin --- pytest.ini | 4 ++++ requirements_test.txt | 6 ++++++ rhodecode/__init__.py | 2 +- rhodecode/config/config_maker.py | 1 - rhodecode/config/environment.py | 3 +-- rhodecode/tests/database/conftest.py | 3 +-- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pytest.ini b/pytest.ini index a5d7bff1..e1bd2486 100644 --- a/pytest.ini +++ b/pytest.ini @@ -21,3 +21,7 @@ markers = skip_backends: Mark tests as skipped for given backends. backends: Mark backends dbs: database markers for running tests for given DB + +env = + RC_TEST=1 + RUN_ENV=test diff --git a/requirements_test.txt b/requirements_test.txt index 72f7f74a..6b09e542 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -11,6 +11,12 @@ pytest-cov==4.0.0 iniconfig==2.0.0 packaging==23.1 pluggy==1.0.0 +pytest-env==1.1.3 + pytest==7.3.1 + attrs==22.2.0 + iniconfig==2.0.0 + packaging==23.1 + pluggy==1.0.0 pytest-rerunfailures==12.0 pytest-profiling==1.7.0 gprof2dot==2022.7.29 diff --git a/rhodecode/__init__.py b/rhodecode/__init__.py index 541a3418..2d6446aa 100644 --- a/rhodecode/__init__.py +++ b/rhodecode/__init__.py @@ -87,5 +87,5 @@ __license__ = 'AGPLv3, and Commercial License' __author__ = 'RhodeCode GmbH' __url__ = 'https://code.rhodecode.com' -is_test = False +is_test = os.getenv('RC_TEST') disable_error_handler = False diff --git a/rhodecode/config/config_maker.py b/rhodecode/config/config_maker.py index d27897fe..9587c0b8 100644 --- a/rhodecode/config/config_maker.py +++ b/rhodecode/config/config_maker.py @@ -92,7 +92,6 @@ def sanitize_settings_and_apply_defaults(global_config, settings): # Sanitize generic settings. settings_maker.make_setting('default_encoding', 'UTF-8', parser='list') - settings_maker.make_setting('is_test', False, parser='bool') settings_maker.make_setting('gzip_responses', False, parser='bool') settings_maker.make_setting('startup.import_repos', 'false', parser='bool') diff --git a/rhodecode/config/environment.py b/rhodecode/config/environment.py index 376cad85..20ee0f38 100644 --- a/rhodecode/config/environment.py +++ b/rhodecode/config/environment.py @@ -46,8 +46,7 @@ def load_pyramid_environment(global_config, settings): # If this is a test run we prepare the test environment like # creating a test database, test search index and test repositories. # This has to be done before the database connection is initialized. - if settings['is_test']: - rhodecode.is_test = True + if rhodecode.is_test: rhodecode.disable_error_handler = True from rhodecode import authentication authentication.plugin_default_auth_ttl = 0 diff --git a/rhodecode/tests/database/conftest.py b/rhodecode/tests/database/conftest.py index 26e67da7..7799f23c 100644 --- a/rhodecode/tests/database/conftest.py +++ b/rhodecode/tests/database/conftest.py @@ -86,8 +86,7 @@ class DBBackend(object): _store = os.path.dirname(os.path.abspath(__file__)) _type = None _base_ini_config = [{'app:main': {'vcs.start_server': 'false', - 'startup.import_repos': 'false', - 'is_test': 'False'}}] + 'startup.import_repos': 'false'}}] _db_url = [{'app:main': {'sqlalchemy.db1.url': ''}}] _base_db_name = 'rhodecode_test_db_backend'