diff --git a/scripts/python_tests.sh b/scripts/python_tests.sh index cbad0c58bdc83..d34e605a21caa 100755 --- a/scripts/python_tests.sh +++ b/scripts/python_tests.sh @@ -19,6 +19,7 @@ set -e export SUPERSET_CONFIG=${SUPERSET_CONFIG:-tests.superset_test_config} +export SUPERSET_TESTENV=true echo "Superset config module: $SUPERSET_CONFIG" superset db upgrade diff --git a/superset/config.py b/superset/config.py index 52566af7b6ff1..7b840d43fa953 100644 --- a/superset/config.py +++ b/superset/config.py @@ -42,6 +42,7 @@ ) from superset.stats_logger import DummyStatsLogger from superset.typing import CacheConfig +from superset.utils.core import is_test from superset.utils.log import DBEventLogger from superset.utils.logging_configurator import DefaultLoggingConfigurator @@ -629,11 +630,11 @@ class CeleryConfig: # pylint: disable=too-few-public-methods # db configuration and a result of this function. # mypy doesn't catch that if case ensures list content being always str -ALLOWED_USER_CSV_SCHEMA_FUNC: Callable[ - ["Database", "models.User"], List[str] -] = lambda database, user: [ - UPLOADED_CSV_HIVE_NAMESPACE -] if UPLOADED_CSV_HIVE_NAMESPACE else [] +ALLOWED_USER_CSV_SCHEMA_FUNC: Callable[["Database", "models.User"], List[str]] = ( + lambda database, user: [UPLOADED_CSV_HIVE_NAMESPACE] + if UPLOADED_CSV_HIVE_NAMESPACE + else [] +) # Values that should be treated as nulls for the csv uploads. CSV_DEFAULT_NA_NAMES = list(STR_NA_VALUES) @@ -952,7 +953,7 @@ class CeleryConfig: # pylint: disable=too-few-public-methods "Failed to import config for %s=%s", CONFIG_PATH_ENV_VAR, cfg_path ) raise -elif importlib.util.find_spec("superset_config"): +elif importlib.util.find_spec("superset_config") and not is_test(): try: import superset_config # pylint: disable=import-error from superset_config import * # type: ignore # pylint: disable=import-error,wildcard-import,unused-wildcard-import diff --git a/superset/utils/core.py b/superset/utils/core.py index 541d24b411d07..9ab824632e115 100644 --- a/superset/utils/core.py +++ b/superset/utils/core.py @@ -31,6 +31,7 @@ import uuid import zlib from datetime import date, datetime, time, timedelta +from distutils.util import strtobool from email.mime.application import MIMEApplication from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart @@ -1553,3 +1554,7 @@ class AdhocMetricExpressionType(str, Enum): class RowLevelSecurityFilterType(str, Enum): REGULAR = "Regular" BASE = "Base" + + +def is_test() -> bool: + return strtobool(os.environ.get("SUPERSET_TESTENV", "false")) diff --git a/tox.ini b/tox.ini index cbbdb5a718376..b4df8b0256a81 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,7 @@ deps = -rrequirements/testing.txt setenv = PYTHONPATH = {toxinidir} + SUPERSET_TESTENV = true SUPERSET_CONFIG = tests.superset_test_config SUPERSET_HOME = {envtmpdir} mysql: SUPERSET__SQLALCHEMY_DATABASE_URI = mysql://mysqluser:mysqluserpassword@localhost/superset?charset=utf8