Skip to content

Commit

Permalink
Make integration tests work with dbt==1.5 (#323)
Browse files Browse the repository at this point in the history
* Mirror of dbt-databricks#319 but rebased on 1.5.test branch
* Fix: test_fail_fast failure
This is failing because the new dbt-core test runner doesn't re-raise the
initial FailFastException as of dbt-core==1.5.0rc2
* Fix: log message in `impl.py` completely breaks docs generation for
integration tests. This is a mirror of: https: //github.com/dbt-labs/dbt-spark/pull/698
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
  • Loading branch information
susodapop authored and andrefurlan-db committed May 2, 2023
1 parent 8965c2e commit a2de545
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/databricks/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def _get_one_catalog(
quote_policy=self.config.quoting,
)
for relation, information in self._list_relations_with_information(schema_relation):
logger.debug("Getting table schema for relation {}", relation)
logger.debug("Getting table schema for relation {}", str(relation))
columns.extend(self._get_columns_for_catalog(relation, information))
return Table.from_object(columns, column_types=DEFAULT_TYPE_TESTER)

Expand Down
23 changes: 16 additions & 7 deletions tests/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import yaml
from unittest.mock import patch

import dbt.main as dbt # type: ignore
from dbt import flags
from argparse import Namespace
from dbt.cli.main import dbtRunner
import dbt.flags as flags
from dbt.deprecations import reset_deprecations
from dbt.adapters.factory import get_adapter, reset_adapters, register_adapter
from dbt.clients.jinja import template_cache
Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(self, kwargs):
self.profiles_dir = None
self.project_dir = None
self.__dict__.update(kwargs)
self.threads = None


def _profile_from_test_name(test_name):
Expand Down Expand Up @@ -218,14 +220,21 @@ def _generate_test_root_dir(self):
return normalize(tempfile.mkdtemp(prefix="dbt-int-test-"))

def setUp(self):
self.dbt_core_install_root = os.path.dirname(dbt.__file__)
log_manager.reset_handlers()
self.initial_dir = INITIAL_ROOT
os.chdir(self.initial_dir)
# before we go anywhere, collect the initial path info
self._logs_dir = os.path.join(self.initial_dir, "logs", self.prefix)
setup_event_logger(self._logs_dir)
_really_makedirs(self._logs_dir)
args = Namespace(
profiles_dir=".",
project_dir=".",
target=None,
profile=None,
threads=None,
)
flags.set_from_args(args, {})
flags.LOG_PATH = self._logs_dir
setup_event_logger(flags.get_flags())
self.test_original_source_path = _pytest_get_test_root()
self.test_root_dir = self._generate_test_root_dir()

Expand Down Expand Up @@ -427,10 +436,10 @@ def run_dbt_and_check(self, args=None, profiles_dir=True):

if profiles_dir:
final_args.extend(["--profiles-dir", self.test_root_dir])
final_args.append("--log-cache-events")

logger.info("Invoking dbt with {}".format(final_args))
return dbt.handle_and_check(final_args)
res = dbtRunner().invoke(args, log_cache_events=True, log_path=self._logs_dir)
return res.result, res.success

def run_sql_file(self, path, kwargs=None):
with open(path, "r") as f:
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/fail_fast/test_fail_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ def models(self):
def test_fail_fast(self):
self.run_dbt(["run"])

# PECO-738 Original except message we tested for was:
#
# 'Failing early due to test failure or runtime error'
#
# This is supposed to raise a FailFastException but that
# is being swallowed by the test runner and only the DBT
# test failure error message is raised instead.
_ = FailFastError
with self.assertRaisesRegex(
FailFastError, "Failing early due to test failure or runtime error"
Exception, "False != True : dbt exit state did not match expected"
):
self.run_dbt(["test", "--fail-fast"])

Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ deps =
[testenv:integration-databricks-cluster]
basepython = python3
commands =
/bin/bash -c '{envpython} -m pytest -v --profile databricks_cluster -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v -m profile_databricks_cluster -n4 tests/integration/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v --profile databricks_cluster -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
passenv =
DBT_*
PYTEST_ADDOPTS
Expand All @@ -50,8 +50,8 @@ allowlist_externals = /bin/bash
[testenv:integration-databricks-uc-cluster]
basepython = python3
commands =
/bin/bash -c '{envpython} -m pytest -v --profile databricks_uc_cluster -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v -m profile_databricks_uc_cluster -n4 tests/integration/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v --profile databricks_uc_cluster -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
passenv =
DBT_*
PYTEST_ADDOPTS
Expand All @@ -63,8 +63,8 @@ allowlist_externals = /bin/bash
[testenv:integration-databricks-sql-endpoint]
basepython = python3
commands =
/bin/bash -c '{envpython} -m pytest -v --profile databricks_sql_endpoint -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v -m profile_databricks_sql_endpoint -n4 tests/integration/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v --profile databricks_sql_endpoint -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
passenv =
DBT_*
PYTEST_ADDOPTS
Expand All @@ -76,12 +76,12 @@ allowlist_externals = /bin/bash
[testenv:integration-databricks-uc-sql-endpoint]
basepython = python3
commands =
/bin/bash -c '{envpython} -m pytest -v --profile databricks_uc_sql_endpoint -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v -m profile_databricks_uc_sql_endpoint -n4 tests/integration/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
/bin/bash -c '{envpython} -m pytest -v --profile databricks_uc_sql_endpoint -n4 tests/functional/adapter/* {posargs}; ret=$?; [ $ret = 5 ] && exit 0 || exit $ret'
passenv =
DBT_*
PYTEST_ADDOPTS
deps =
-r{toxinidir}/dev-requirements.txt
-r{toxinidir}/requirements.txt
allowlist_externals = /bin/bash
allowlist_externals = /bin/bash

0 comments on commit a2de545

Please sign in to comment.