Skip to content

Commit b8c102d

Browse files
authored
[Fix] Fix Model Serving Test (#781)
## Changes <!-- Summary of your changes that are easy to understand --> Fix Model Serving Tests. - Added preffered auth_type so that test will not use other auth_types first. - Patch function that reads `.databrickscfg`. - Unsetting already existing environment variables. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] `make fmt` applied - [ ] relevant integration tests applied
1 parent a1df7a7 commit b8c102d

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tests/test_model_serving_auth.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,31 @@
1212
"to configure credentials for your preferred authentication method"
1313

1414

15-
@pytest.mark.parametrize(
16-
"env_values, oauth_file_name",
17-
[([('IS_IN_DB_MODEL_SERVING_ENV', 'true'),
18-
('DB_MODEL_SERVING_HOST_URL', 'x')], "tests/testdata/model-serving-test-token"),
19-
([('IS_IN_DATABRICKS_MODEL_SERVING_ENV', 'true'),
20-
('DB_MODEL_SERVING_HOST_URL', 'x')], "tests/testdata/model-serving-test-token"),
21-
([('IS_IN_DB_MODEL_SERVING_ENV', 'true'),
22-
('DATABRICKS_MODEL_SERVING_HOST_URL', 'x')], "tests/testdata/model-serving-test-token"),
23-
([('IS_IN_DATABRICKS_MODEL_SERVING_ENV', 'true'),
24-
('DATABRICKS_MODEL_SERVING_HOST_URL', 'x')], "tests/testdata/model-serving-test-token"), ])
25-
def test_model_serving_auth(env_values, oauth_file_name, monkeypatch):
15+
@pytest.mark.parametrize("env_values, del_env_values, oauth_file_name",
16+
[([
17+
('IS_IN_DB_MODEL_SERVING_ENV', 'true'), ('DB_MODEL_SERVING_HOST_URL', 'x')
18+
], ['DATABRICKS_MODEL_SERVING_HOST_URL'], "tests/testdata/model-serving-test-token"),
19+
([('IS_IN_DATABRICKS_MODEL_SERVING_ENV', 'true'),
20+
('DB_MODEL_SERVING_HOST_URL', 'x')], ['DATABRICKS_MODEL_SERVING_HOST_URL'],
21+
"tests/testdata/model-serving-test-token"),
22+
([('IS_IN_DB_MODEL_SERVING_ENV', 'true'), ('DATABRICKS_MODEL_SERVING_HOST_URL', 'x')
23+
], ['DB_MODEL_SERVING_HOST_URL'], "tests/testdata/model-serving-test-token"),
24+
([('IS_IN_DATABRICKS_MODEL_SERVING_ENV', 'true'),
25+
('DATABRICKS_MODEL_SERVING_HOST_URL', 'x')
26+
], ['DB_MODEL_SERVING_HOST_URL'], "tests/testdata/model-serving-test-token"), ])
27+
def test_model_serving_auth(env_values, del_env_values, oauth_file_name, monkeypatch, mocker):
2628
## In mlflow we check for these two environment variables to return the correct config
2729
for (env_name, env_value) in env_values:
2830
monkeypatch.setenv(env_name, env_value)
31+
32+
for (env_name) in del_env_values:
33+
monkeypatch.delenv(env_name, raising=False)
34+
2935
# patch mlflow to read the file from the test directory
3036
monkeypatch.setattr(
3137
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
3238
oauth_file_name)
39+
mocker.patch('databricks.sdk.config.Config._known_file_config_loader')
3340

3441
cfg = Config()
3542

@@ -58,7 +65,7 @@ def test_model_serving_auth_errors(env_values, oauth_file_name, monkeypatch):
5865
Config()
5966

6067

61-
def test_model_serving_auth_refresh(monkeypatch):
68+
def test_model_serving_auth_refresh(monkeypatch, mocker):
6269
## In mlflow we check for these two environment variables to return the correct config
6370
monkeypatch.setenv('IS_IN_DB_MODEL_SERVING_ENV', 'true')
6471
monkeypatch.setenv('DB_MODEL_SERVING_HOST_URL', 'x')
@@ -67,6 +74,7 @@ def test_model_serving_auth_refresh(monkeypatch):
6774
monkeypatch.setattr(
6875
"databricks.sdk.credentials_provider.ModelServingAuthProvider._MODEL_DEPENDENCY_OAUTH_TOKEN_FILE_PATH",
6976
"tests/testdata/model-serving-test-token")
77+
mocker.patch('databricks.sdk.config.Config._known_file_config_loader')
7078

7179
cfg = Config()
7280
assert cfg.auth_type == 'model-serving'

0 commit comments

Comments
 (0)