Skip to content

Commit

Permalink
Do not import superset_config on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Oct 8, 2020
1 parent b6728d8 commit a6d966a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions scripts/python_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,3 +1553,7 @@ class AdhocMetricExpressionType(str, Enum):
class RowLevelSecurityFilterType(str, Enum):
REGULAR = "Regular"
BASE = "Base"


def is_test() -> bool:
return "SUPERSET_TESTENV" in os.environ
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a6d966a

Please sign in to comment.