From 2e0f558786a106f7a7100a7a897e9433ebe72719 Mon Sep 17 00:00:00 2001 From: Qixiang Wan Date: Feb 07 2020 04:21:03 +0000 Subject: Set FRESHMAKER_TESTING_ENV in testing env If run tests with 'python -m pytest', sys.argv[0] is: '${python_sitepackages_dir}/pytest/__main__.py' this breaks the check of testing environment (in 'init_config'), so we introduce a new env var "FRESHMAKER_TESTING_ENV" and set it in tox testenv. --- diff --git a/freshmaker/config.py b/freshmaker/config.py index 4334df4..5e09906 100644 --- a/freshmaker/config.py +++ b/freshmaker/config.py @@ -79,8 +79,10 @@ def init_config(app): config_section = os.environ['FRESHMAKER_CONFIG_SECTION'] # TestConfiguration shall only be used for running tests, otherwise... + test_env = os.environ.get('FRESHMAKER_TESTING_ENV', '').lower() test_executables = {'py.test', 'pytest', 'pytest.py'} - if os.path.basename(sys.argv[0]) in test_executables: + if (os.path.basename(sys.argv[0]) in test_executables or + test_env in ('1', 'on', 'true', 'y', 'yes')): config_section = 'TestConfiguration' from conf import config config_module = config diff --git a/tox.ini b/tox.ini index 89805e3..cef5396 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ envlist = py37, flake8, bandit [testenv] basepython = python3 +setenv = FRESHMAKER_TESTING_ENV = 1 skip_install = True deps = -r{toxinidir}/test-requirements.txt commands =