Skip to content

Commit

Permalink
fix: do not import superset_config on tests (apache#11193)
Browse files Browse the repository at this point in the history
* Do not import superset_config on tests

* Use strtobool
  • Loading branch information
betodealmeida authored and auxten committed Nov 20, 2020
1 parent 02b5397 commit f5d3474
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
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
3 changes: 2 additions & 1 deletion 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 @@ -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
5 changes: 5 additions & 0 deletions superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1564,3 +1565,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"))
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 f5d3474

Please sign in to comment.