Skip to content

Commit

Permalink
Run integration test against multiple dbconnect install
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikgupta-db committed Feb 26, 2024
1 parent 4b9d8e5 commit 70a609e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test:
pytest -m 'not integration and not benchmark' --cov=databricks --cov-report html tests

integration:
pytest -n auto -m 'integration and not benchmark' --cov=databricks --cov-report html tests
pytest -n auto -m 'integration and not benchmark' --cov=databricks --cov-report html -k 'test_dbconnect.py' tests

benchmark:
pytest -m 'benchmark' tests
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def ucws(env_or_skip) -> WorkspaceClient:
@pytest.fixture(scope='session')
def env_or_skip():

def inner(var) -> str:
def inner(var: str) -> str:
if var not in os.environ:
pytest.skip(f'Environment variable {var} is missing')
return os.environ[var]
Expand Down
48 changes: 48 additions & 0 deletions tests/integration/test_dbconnect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from contextlib import contextmanager

import pytest

DBCONNECT_DBR_CLIENT = {
"13.3": "13.3.3",
"14.3": "14.3.1",
}

@pytest.fixture(scope="function")
def restorable_env():
import os
current_env = os.environ.copy()
yield
for k, v in os.environ.items():
if k not in current_env:
del os.environ[k]
elif v != current_env[k]:
os.environ[k] = current_env[k]

@pytest.fixture()
def setup_dbconnect_test(dbr: str, env_or_skip, restorable_env):
assert dbr in DBCONNECT_DBR_CLIENT, f"Unsupported Databricks Runtime version {dbr}. Please update DBCONNECT_DBR_CLIENT."

import os
os.environ["DATABRICKS_CLUSTER_ID"] = env_or_skip(f"TEST_DBR_{dbr.replace('.', '_')}_DBCONNECT_CLUSTER_ID")

import sys
import subprocess
lib = f"databricks-dbconnect=={DBCONNECT_DBR_CLIENT[dbr]}"
subprocess.check_call([sys.executable, "-m", "pip", "install", lib])

yield

subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "-y", lib])


@pytest.mark.parametrize("dbr", DBCONNECT_DBR_CLIENT.keys(), indirect=True)
def test_dbconnect_initialisation(w, setup_dbconnect_test):
from databricks.connect import DatabricksSession
spark = DatabricksSession.builder.getOrCreate()
assert spark.sql("SELECT 1").collect()[0][0] == 1

@pytest.mark.parametrize("dbr", DBCONNECT_DBR_CLIENT.keys(), indirect=True)
def test_dbconnect_runtime_import(w, setup_dbconnect_test):
from databricks.sdk.runtime import *
assert spark.sql("SELECT 1").collect()[0][0] == 1

30 changes: 0 additions & 30 deletions tests/integration/test_local_globals.py

This file was deleted.

0 comments on commit 70a609e

Please sign in to comment.