Skip to content

Commit ad3fb5b

Browse files
authored
Fix failing unit tests (#282)
## Changes This PR works around a behaviour change introduced by Databricks SDK v0.102.0 that causes unit tests to fail if they are using the `Config` class. Specifically, during `__init__()` the `Config()` class now performs a HTTP request against the host, and retries for 5 minutes if the host does not exist. Unit tests typically fill in a bogus host, which was fine previously because initialising `Config` was inert and didn't trigger network calls. Now that it does, some sort of workaround (such as monkey-patching) is required. Incidental change: - Dependency-management for the project was out-of-date, and stopped working because the lockfile referred directly to an internal PyPi proxy that is no longer intended for use. As such the plumbing for locking dependencies was updated, and the lockfile regenerated. ### Linked issues Tests, same as: databrickslabs/blueprint#331 For `Makefile`, same as: databrickslabs/blueprint#392 ### Tests - updated unit tests
1 parent f50f0ae commit ad3fb5b

6 files changed

Lines changed: 393 additions & 378 deletions

File tree

.build-constraints.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
hatchling==1.29.0 \
2-
--hash=sha256:50af9343281f34785fab12da82e445ed987a6efb34fd8c2fc0f6e6630dbcc1b0 \
3-
--hash=sha256:793c31816d952cee405b83488ce001c719f325d9cda69f1fc4cd750527640ea6
4-
packaging==26.0 \
5-
--hash=sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4 \
6-
--hash=sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529
1+
hatchling==1.30.1 \
2+
--hash=sha256:161eacafb3c6f91526e92116d21426369f2c36e98c36a864f11a96345ad4ee31 \
3+
--hash=sha256:eee4fd45357f72ebb3d7a42e5d72cfb5e29ed426d79e8836288926c4258d5f2e
4+
packaging==26.2 \
5+
--hash=sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e \
6+
--hash=sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661
77
# via hatchling
8-
pathspec==1.0.4 \
9-
--hash=sha256:0210e2ae8a21a9137c0d470578cb0e595af87edaa6ebf12ff176f14a02e0e645 \
10-
--hash=sha256:fb6ae2fd4e7c921a165808a552060e722767cfa526f99ca5156ed2ce45a5c723
8+
pathspec==1.1.1 \
9+
--hash=sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a \
10+
--hash=sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189
1111
# via hatchling
1212
pluggy==1.6.0 \
1313
--hash=sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3 \
@@ -62,7 +62,7 @@ tomli==2.4.1 ; python_full_version < '3.11' \
6262
--hash=sha256:ff18e6a727ee0ab0388507b89d1bc6a22b138d1e2fa56d1ad494586d61d2eae9 \
6363
--hash=sha256:ff2983983d34813c1aeb0fa89091e76c3a22889ee83ab27c5eeb45100560c049
6464
# via hatchling
65-
trove-classifiers==2026.1.14.14 \
66-
--hash=sha256:00492545a1402b09d4858605ba190ea33243d361e2b01c9c296ce06b5c3325f3 \
67-
--hash=sha256:1f9553927f18d0513d8e5ff80ab8980b8202ce37ecae0e3274ed2ef11880e74d
65+
trove-classifiers==2026.6.1.19 \
66+
--hash=sha256:ab4c4ec93cc4a4e7815fa759906e05e6bb3f2fbd92ea0f897288c6a43efd15b3 \
67+
--hash=sha256:c5132b4b61a829d11cfbd2d72e97f20a45ed6edb95e45c5efdeb5e00836b2745
6868
# via hatchling

Makefile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
all: clean lint fmt test coverage
22

3-
# Ensure that all uv commands don't automatically update the lock file. If UV_FROZEN=1 (from the environment)
4-
# then UV_LOCKED should _not_ be set, but otherwise it needs to be set to ensure the lock-file is only ever
5-
# deliberately updated.
6-
ifneq ($(UV_FROZEN),1)
7-
export UV_LOCKED := 1
8-
endif
3+
# Ensure that all uv commands don't automatically update the lock file: instead they use the locked dependencies.
4+
export UV_FROZEN := 1
95
# Ensure that hatchling is pinned when builds are needed.
106
export UV_BUILD_CONSTRAINT := .build-constraints.txt
117

@@ -45,12 +41,17 @@ coverage:
4541
build:
4642
uv build --require-hashes --build-constraints=.build-constraints.txt
4743

48-
lock-dependencies: UV_LOCKED := 0
44+
lock-dependencies: UV_FROZEN := 0
4945
lock-dependencies:
50-
uv lock
46+
uv lock --upgrade
5147
$(UV_RUN) --group yq tomlq -r '.["build-system"].requires[]' pyproject.toml | \
52-
uv pip compile --generate-hashes --universal --no-header - > build-constraints-new.txt
48+
uv pip compile --upgrade --generate-hashes --universal --no-header --quiet - > build-constraints-new.txt
5349
mv build-constraints-new.txt .build-constraints.txt
50+
@perl -pi \
51+
-e 's|registry = "https://[^"]*"|registry = "https://pypi.org/simple"|g;' \
52+
-e 's|url = "https://[^"]*/packages/([^"]*)"|url = "https://files.pythonhosted.org/packages/$$1"|g;' \
53+
uv.lock
54+
@printf 'Stripped registry references from uv.lock.\n'
5455

5556
.DEFAULT: all
5657
.PHONY: all clean dev lint fmt test integration coverage build lock-dependencies

tests/unit/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
import pytest
2+
3+
from databricks.sdk.config import Config
4+
15
pytest_plugins = ['pytester']
6+
7+
8+
@pytest.fixture
9+
def db_config_no_side_effect(monkeypatch: pytest.MonkeyPatch) -> None:
10+
"""Suspend host metadata lookups from the SDKs Config class.
11+
12+
As of version 0.102.0 of the Databricks SDK, the `Config` class during __init__() makes a network call with a
13+
timeout of 5 minutes if the target host does not exist. For unit tests, it never does. This fixture therefore
14+
patches over that lookup to ensure it doesn't get in the way of our tests.
15+
"""
16+
17+
monkeypatch.setattr(Config, "_resolve_host_metadata", lambda _: None)

tests/unit/fixtures/test_baseline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from databricks.labs.pytester.fixtures.sql import sql_backend
1010

1111

12-
def test_ws() -> None:
12+
def test_ws(db_config_no_side_effect: None) -> None:
1313
debug_env = {'DATABRICKS_HOST': 'abc', 'DATABRICKS_TOKEN': '...'}
1414
product_info = 'a', '0.1.2'
1515
workspace_client = call_fixture(ws, debug_env, product_info)

tests/unit/fixtures/test_iam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_make_user_no_args() -> None:
1717
ctx['ws'].users.delete.assert_called_once()
1818

1919

20-
def test_make_run_as_no_args() -> None:
20+
def test_make_run_as_no_args(db_config_no_side_effect: None) -> None:
2121
ctx, run_as = call_stateful(make_run_as)
2222
assert ctx is not None
2323
assert run_as is not None

0 commit comments

Comments
 (0)