Skip to content

Commit 2590d3c

Browse files
authored
Move remaining UCX integration tests and fixtures (#45)
1 parent 246c3de commit 2590d3c

File tree

6 files changed

+71
-10
lines changed

6 files changed

+71
-10
lines changed

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [Ecosystem](#ecosystem)
1010
* [PyTest Fixtures](#pytest-fixtures)
1111
* [Logging](#logging)
12+
* [Installation](#installation)
1213
* [`debug_env_name` fixture](#debug_env_name-fixture)
1314
* [`debug_env` fixture](#debug_env-fixture)
1415
* [`env_or_skip` fixture](#env_or_skip-fixture)
@@ -74,6 +75,41 @@ also install it directly from the command line:
7475
pip install databricks-labs-pytester
7576
```
7677

78+
If you use `hatch` as a build system, make sure to add `databricks-labs-pytester` as
79+
a test-time dependency and not as a compile-time dependency, otherwise your wheels will
80+
transitively depend on `pytest`, which is not usually something you need.
81+
82+
```toml
83+
[project]
84+
name = "name-of-your-project"
85+
# ...
86+
dependencies = [
87+
"databricks-sdk~=0.30",
88+
# ... dependencies required for your code to execute
89+
]
90+
91+
[tool.hatch.envs.default]
92+
dependencies = [
93+
# ... dependencies required to test/validate/format your code:
94+
"black~=24.3.0",
95+
"coverage[toml]~=7.4.4",
96+
"mypy~=1.9.0",
97+
"pylint~=3.2.2",
98+
"pylint-pytest==2.0.0a0",
99+
"databricks-labs-pylint~=0.4.0",
100+
"databricks-labs-pytester~=0.2", # <= this library
101+
"pytest~=8.3.3",
102+
"pytest-cov~=4.1.0",
103+
"pytest-mock~=3.14.0",
104+
"pytest-timeout~=2.3.1",
105+
"pytest-xdist~=3.5.0",
106+
"python-lsp-server>=1.9.0",
107+
"ruff~=0.3.4",
108+
"types-PyYAML~=6.0.12",
109+
"types-requests~=2.31.0",
110+
]
111+
```
112+
77113
[[back to top](#python-testing-for-databricks)]
78114

79115
## Ecosystem
@@ -242,7 +278,7 @@ def test_workspace_operations(ws):
242278
assert len(clusters) >= 0
243279
```
244280

245-
See also [`log_workspace_link`](#log_workspace_link-fixture), [`make_alert_permissions`](#make_alert_permissions-fixture), [`make_authorization_permissions`](#make_authorization_permissions-fixture), [`make_catalog`](#make_catalog-fixture), [`make_cluster`](#make_cluster-fixture), [`make_cluster_permissions`](#make_cluster_permissions-fixture), [`make_cluster_policy`](#make_cluster_policy-fixture), [`make_cluster_policy_permissions`](#make_cluster_policy_permissions-fixture), [`make_dashboard_permissions`](#make_dashboard_permissions-fixture), [`make_directory`](#make_directory-fixture), [`make_directory_permissions`](#make_directory_permissions-fixture), [`make_experiment`](#make_experiment-fixture), [`make_experiment_permissions`](#make_experiment_permissions-fixture), [`make_feature_table_permissions`](#make_feature_table_permissions-fixture), [`make_group`](#make_group-fixture), [`make_instance_pool`](#make_instance_pool-fixture), [`make_instance_pool_permissions`](#make_instance_pool_permissions-fixture), [`make_job`](#make_job-fixture), [`make_job_permissions`](#make_job_permissions-fixture), [`make_lakeview_dashboard_permissions`](#make_lakeview_dashboard_permissions-fixture), [`make_model`](#make_model-fixture), [`make_notebook`](#make_notebook-fixture), [`make_notebook_permissions`](#make_notebook_permissions-fixture), [`make_pipeline`](#make_pipeline-fixture), [`make_pipeline_permissions`](#make_pipeline_permissions-fixture), [`make_query`](#make_query-fixture), [`make_query_permissions`](#make_query_permissions-fixture), [`make_registered_model_permissions`](#make_registered_model_permissions-fixture), [`make_repo`](#make_repo-fixture), [`make_repo_permissions`](#make_repo_permissions-fixture), [`make_secret_scope`](#make_secret_scope-fixture), [`make_secret_scope_acl`](#make_secret_scope_acl-fixture), [`make_serving_endpoint`](#make_serving_endpoint-fixture), [`make_serving_endpoint_permissions`](#make_serving_endpoint_permissions-fixture), [`make_storage_credential`](#make_storage_credential-fixture), [`make_udf`](#make_udf-fixture), [`make_user`](#make_user-fixture), [`make_warehouse`](#make_warehouse-fixture), [`make_warehouse_permissions`](#make_warehouse_permissions-fixture), [`make_workspace_file_path_permissions`](#make_workspace_file_path_permissions-fixture), [`make_workspace_file_permissions`](#make_workspace_file_permissions-fixture), [`spark`](#spark-fixture), [`sql_backend`](#sql_backend-fixture), [`debug_env`](#debug_env-fixture), [`product_info`](#product_info-fixture).
281+
See also [`log_workspace_link`](#log_workspace_link-fixture), [`make_alert_permissions`](#make_alert_permissions-fixture), [`make_authorization_permissions`](#make_authorization_permissions-fixture), [`make_catalog`](#make_catalog-fixture), [`make_cluster`](#make_cluster-fixture), [`make_cluster_permissions`](#make_cluster_permissions-fixture), [`make_cluster_policy`](#make_cluster_policy-fixture), [`make_cluster_policy_permissions`](#make_cluster_policy_permissions-fixture), [`make_dashboard_permissions`](#make_dashboard_permissions-fixture), [`make_directory`](#make_directory-fixture), [`make_directory_permissions`](#make_directory_permissions-fixture), [`make_experiment`](#make_experiment-fixture), [`make_experiment_permissions`](#make_experiment_permissions-fixture), [`make_feature_table`](#make_feature_table-fixture), [`make_feature_table_permissions`](#make_feature_table_permissions-fixture), [`make_group`](#make_group-fixture), [`make_instance_pool`](#make_instance_pool-fixture), [`make_instance_pool_permissions`](#make_instance_pool_permissions-fixture), [`make_job`](#make_job-fixture), [`make_job_permissions`](#make_job_permissions-fixture), [`make_lakeview_dashboard_permissions`](#make_lakeview_dashboard_permissions-fixture), [`make_model`](#make_model-fixture), [`make_notebook`](#make_notebook-fixture), [`make_notebook_permissions`](#make_notebook_permissions-fixture), [`make_pipeline`](#make_pipeline-fixture), [`make_pipeline_permissions`](#make_pipeline_permissions-fixture), [`make_query`](#make_query-fixture), [`make_query_permissions`](#make_query_permissions-fixture), [`make_registered_model_permissions`](#make_registered_model_permissions-fixture), [`make_repo`](#make_repo-fixture), [`make_repo_permissions`](#make_repo_permissions-fixture), [`make_secret_scope`](#make_secret_scope-fixture), [`make_secret_scope_acl`](#make_secret_scope_acl-fixture), [`make_serving_endpoint`](#make_serving_endpoint-fixture), [`make_serving_endpoint_permissions`](#make_serving_endpoint_permissions-fixture), [`make_storage_credential`](#make_storage_credential-fixture), [`make_udf`](#make_udf-fixture), [`make_user`](#make_user-fixture), [`make_warehouse`](#make_warehouse-fixture), [`make_warehouse_permissions`](#make_warehouse_permissions-fixture), [`make_workspace_file_path_permissions`](#make_workspace_file_path_permissions-fixture), [`make_workspace_file_permissions`](#make_workspace_file_permissions-fixture), [`spark`](#spark-fixture), [`sql_backend`](#sql_backend-fixture), [`debug_env`](#debug_env-fixture), [`product_info`](#product_info-fixture).
246282

247283

248284
[[back to top](#python-testing-for-databricks)]
@@ -336,7 +372,7 @@ random_string = make_random(k=8)
336372
assert len(random_string) == 8
337373
```
338374

339-
See also [`make_acc_group`](#make_acc_group-fixture), [`make_catalog`](#make_catalog-fixture), [`make_cluster`](#make_cluster-fixture), [`make_cluster_policy`](#make_cluster_policy-fixture), [`make_directory`](#make_directory-fixture), [`make_experiment`](#make_experiment-fixture), [`make_group`](#make_group-fixture), [`make_instance_pool`](#make_instance_pool-fixture), [`make_job`](#make_job-fixture), [`make_model`](#make_model-fixture), [`make_notebook`](#make_notebook-fixture), [`make_pipeline`](#make_pipeline-fixture), [`make_query`](#make_query-fixture), [`make_repo`](#make_repo-fixture), [`make_schema`](#make_schema-fixture), [`make_secret_scope`](#make_secret_scope-fixture), [`make_serving_endpoint`](#make_serving_endpoint-fixture), [`make_table`](#make_table-fixture), [`make_udf`](#make_udf-fixture), [`make_user`](#make_user-fixture), [`make_warehouse`](#make_warehouse-fixture).
375+
See also [`make_acc_group`](#make_acc_group-fixture), [`make_catalog`](#make_catalog-fixture), [`make_cluster`](#make_cluster-fixture), [`make_cluster_policy`](#make_cluster_policy-fixture), [`make_directory`](#make_directory-fixture), [`make_experiment`](#make_experiment-fixture), [`make_feature_table`](#make_feature_table-fixture), [`make_group`](#make_group-fixture), [`make_instance_pool`](#make_instance_pool-fixture), [`make_job`](#make_job-fixture), [`make_model`](#make_model-fixture), [`make_notebook`](#make_notebook-fixture), [`make_pipeline`](#make_pipeline-fixture), [`make_query`](#make_query-fixture), [`make_repo`](#make_repo-fixture), [`make_schema`](#make_schema-fixture), [`make_secret_scope`](#make_secret_scope-fixture), [`make_serving_endpoint`](#make_serving_endpoint-fixture), [`make_table`](#make_table-fixture), [`make_udf`](#make_udf-fixture), [`make_user`](#make_user-fixture), [`make_warehouse`](#make_warehouse-fixture).
340376

341377

342378
[[back to top](#python-testing-for-databricks)]
@@ -370,7 +406,8 @@ See also [`ws`](#ws-fixture).
370406
[[back to top](#python-testing-for-databricks)]
371407

372408
### `make_job` fixture
373-
Create a Databricks job and clean it up after the test. Returns a function to create jobs.
409+
Create a Databricks job and clean it up after the test. Returns a function to create jobs, that returns
410+
a [`Job`](https://databricks-sdk-py.readthedocs.io/en/latest/dbdataclasses/jobs.html#databricks.sdk.service.jobs.Job) instance.
374411

375412
Keyword Arguments:
376413
* `notebook_path` (str, optional): The path to the notebook. If not provided, a random notebook will be created.
@@ -1046,6 +1083,14 @@ _No description yet._
10461083
See also [`ws`](#ws-fixture).
10471084

10481085

1086+
[[back to top](#python-testing-for-databricks)]
1087+
1088+
### `make_feature_table` fixture
1089+
_No description yet._
1090+
1091+
See also [`ws`](#ws-fixture), [`make_random`](#make_random-fixture).
1092+
1093+
10491094
[[back to top](#python-testing-for-databricks)]
10501095

10511096
### `make_feature_table_permissions` fixture

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ coverage = "pytest -n auto --cov src tests/unit --timeout 30 --cov-report=htm
8888
integration = "pytest -n 10 --cov src tests/integration --durations 20"
8989
fmt = ["black . --extend-exclude 'tests/unit/source_code/samples/'",
9090
"ruff check . --fix",
91-
"mypy --disable-error-code 'annotation-unchecked' --enable-incomplete-feature=NewGenericSyntax --exclude 'tests/resources/*' --exclude dist .",
91+
"mypy --disable-error-code 'annotation-unchecked' --disable-error-code import-untyped --enable-incomplete-feature=NewGenericSyntax --exclude 'tests/resources/*' --exclude dist .",
9292
"pylint --output-format=colorized -j 0 src tests"]
9393
verify = ["black --check . --extend-exclude 'tests/unit/source_code/samples/'",
9494
"ruff check .",

src/databricks/labs/pytester/fixtures/compute.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def create(*, instance_pool_name=None, node_type_id=None, **kwargs) -> CreateIns
157157
@fixture
158158
def make_job(ws, make_random, make_notebook, log_workspace_link, watchdog_remove_after) -> Generator[Job, None, None]:
159159
"""
160-
Create a Databricks job and clean it up after the test. Returns a function to create jobs.
160+
Create a Databricks job and clean it up after the test. Returns a function to create jobs, that returns
161+
a `databricks.sdk.service.jobs.Job` instance.
161162
162163
Keyword Arguments:
163164
* `notebook_path` (str, optional): The path to the notebook. If not provided, a random notebook will be created.
@@ -211,7 +212,7 @@ def create(notebook_path: str | Path | None = None, **kwargs) -> Job:
211212
kwargs["tags"].append(remove_after_tag)
212213
job = ws.jobs.create(**kwargs)
213214
log_workspace_link(kwargs["name"], f'job/{job.job_id}', anchor=False)
214-
return job
215+
return ws.jobs.get(job.job_id)
215216

216217
yield from factory("job", create, lambda item: ws.jobs.delete(item.job_id))
217218

src/databricks/labs/pytester/fixtures/ml.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,20 @@ def remove(endpoint_name: str):
145145
ws.serving_endpoints.delete(endpoint_name)
146146

147147
yield from factory("Serving endpoint", create, remove)
148+
149+
150+
@fixture
151+
def make_feature_table(ws, make_random):
152+
def create():
153+
feature_table_name = make_random(6) + "." + make_random(6)
154+
table = ws.api_client.do(
155+
"POST",
156+
"/api/2.0/feature-store/feature-tables/create",
157+
body={"name": feature_table_name, "primary_keys": [{"name": "pk", "data_type": "string"}]},
158+
)
159+
return table['feature_table']
160+
161+
def remove(table: dict):
162+
ws.api_client.do("DELETE", "/api/2.0/feature-store/feature-tables/delete", body={"name": table["name"]})
163+
164+
yield from factory("Feature table", create, remove)

src/databricks/labs/pytester/fixtures/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
)
5050
from databricks.labs.pytester.fixtures.secrets import make_secret_scope, make_secret_scope_acl
5151
from databricks.labs.pytester.fixtures.environment import debug_env, debug_env_name, env_or_skip, is_in_debug
52-
from databricks.labs.pytester.fixtures.ml import make_experiment, make_model, make_serving_endpoint
52+
from databricks.labs.pytester.fixtures.ml import make_experiment, make_model, make_serving_endpoint, make_feature_table
5353
from databricks.labs.pytester.fixtures.redash import make_query
5454
from databricks.labs.pytester.fixtures.watchdog import watchdog_remove_after, watchdog_purge_suffix
5555
from databricks.labs.pytester.fixtures.connect import spark
@@ -109,6 +109,7 @@
109109
'make_registered_model_permissions',
110110
'make_serving_endpoint',
111111
'make_serving_endpoint_permissions',
112+
'make_feature_table',
112113
'make_feature_table_permissions',
113114
'watchdog_remove_after',
114115
'watchdog_purge_suffix',

tests/integration/fixtures/test_catalog.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
import pytest
33

44

5-
6-
7-
85
logger = logging.getLogger(__name__)
96

107

0 commit comments

Comments
 (0)