Skip to content

Commit f989668

Browse files
committed
Use __file__-relative path for test_model_serving_auth fixtures
test_model_serving_auth.py hardcoded "tests/testdata/model-serving- test-token" assuming cwd == SDK root. That works for the upstream `make test` invocation but breaks when pytest is launched from any other directory (e.g. a Bazel test sandbox). Switch to `pathlib.Path(__file__).parent / "testdata" / ...` so the tests resolve their fixtures regardless of cwd.
1 parent 0ef5cc2 commit f989668

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

tests/test_model_serving_auth.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib
12
import threading
23
import time
34

@@ -8,6 +9,12 @@
89

910
from .conftest import raises
1011

12+
# Test fixture files live next to this test, regardless of where pytest
13+
# was invoked from.
14+
_TESTDATA = pathlib.Path(__file__).parent / "testdata"
15+
_MODEL_SERVING_TEST_TOKEN = str(_TESTDATA / "model-serving-test-token")
16+
_MODEL_SERVING_TEST_TOKEN_V2 = str(_TESTDATA / "model-serving-test-token-v2")
17+
1118
default_auth_base_error_message = (
1219
"default auth: cannot configure default credentials, "
1320
"please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication "
@@ -24,31 +31,31 @@
2431
("DB_MODEL_SERVING_HOST_URL", "x"),
2532
],
2633
["DATABRICKS_MODEL_SERVING_HOST_URL"],
27-
"tests/testdata/model-serving-test-token",
34+
_MODEL_SERVING_TEST_TOKEN,
2835
),
2936
(
3037
[
3138
("IS_IN_DATABRICKS_MODEL_SERVING_ENV", "true"),
3239
("DB_MODEL_SERVING_HOST_URL", "x"),
3340
],
3441
["DATABRICKS_MODEL_SERVING_HOST_URL"],
35-
"tests/testdata/model-serving-test-token",
42+
_MODEL_SERVING_TEST_TOKEN,
3643
),
3744
(
3845
[
3946
("IS_IN_DB_MODEL_SERVING_ENV", "true"),
4047
("DATABRICKS_MODEL_SERVING_HOST_URL", "x"),
4148
],
4249
["DB_MODEL_SERVING_HOST_URL"],
43-
"tests/testdata/model-serving-test-token",
50+
_MODEL_SERVING_TEST_TOKEN,
4451
),
4552
(
4653
[
4754
("IS_IN_DATABRICKS_MODEL_SERVING_ENV", "true"),
4855
("DATABRICKS_MODEL_SERVING_HOST_URL", "x"),
4956
],
5057
["DB_MODEL_SERVING_HOST_URL"],
51-
"tests/testdata/model-serving-test-token",
58+
_MODEL_SERVING_TEST_TOKEN,
5259
),
5360
],
5461
)
@@ -92,7 +99,7 @@ def test_model_serving_auth(env_values, del_env_values, oauth_file_name, monkeyp
9299
), # In Model Serving and Invalid File Name
93100
(
94101
[],
95-
"tests/testdata/model-serving-test-token",
102+
_MODEL_SERVING_TEST_TOKEN,
96103
), # Not in Model Serving and Valid File Name
97104
],
98105
)
@@ -122,7 +129,7 @@ def test_model_serving_auth_refresh(monkeypatch, mocker):
122129
# patch mlflow to read the file from the test directory
123130
monkeypatch.setattr(
124131
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
125-
"tests/testdata/model-serving-test-token",
132+
_MODEL_SERVING_TEST_TOKEN,
126133
)
127134
mocker.patch("databricks.sdk.config.Config._known_file_config_loader")
128135

@@ -136,7 +143,7 @@ def test_model_serving_auth_refresh(monkeypatch, mocker):
136143
# Simulate refreshing the token by patching to to a new file
137144
monkeypatch.setattr(
138145
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
139-
"tests/testdata/model-serving-test-token-v2",
146+
_MODEL_SERVING_TEST_TOKEN_V2,
140147
)
141148

142149
monkeypatch.setattr(
@@ -172,7 +179,7 @@ def test_agent_user_credentials(monkeypatch, mocker):
172179
monkeypatch.setenv("DB_MODEL_SERVING_HOST_URL", "x")
173180
monkeypatch.setattr(
174181
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
175-
"tests/testdata/model-serving-test-token",
182+
_MODEL_SERVING_TEST_TOKEN,
176183
)
177184

178185
invokers_token_val = "databricks_invokers_token"

0 commit comments

Comments
 (0)