Commit d19f143
authored
Make DB Connect work out of the box for unit tests with the default-python template (#3254)
## Changes
This update `default-python` to make DB Connect work out of the box:
* We now install a conservative 15.x version of DB Connect using uv
(14.x is even older and doesn't support serverless)
* We validate that the current DB Connect version is supported by the
remote cluster / serverless compute. Note that the VS Code extension
also does this, providing a warning when users attempt to run against an
older cluster.
* We make sure there's always a valid SparkSession during test execution
(even when users write standard Spark / Spark Declarative Pipelines code
with `SparkSessions.builder.getOrCreate()`)
* We fall back to serverless compute when the user didn't manually
configure a cluster. This also addresses known a current issue with the
VS Code extension where it doesn't provide a cluster id when using 'Run'
rather than 'Debug' to execute unit tests.
* We validate that test dependencies are installed and report a friendly
error if they are not.
## Usage
1. Install via `bundle init`
```
lennart:demo$ databricks bundle init
Template to use: python-default
Welcome to the default Python template for Databricks Asset Bundles!
Please provide the following details to tailor the template to your preferences.
Unique name for this project [my_project]: my_project
Include a stub (sample) notebook in 'my_project/src': yes
Include a stub (sample) Delta Live Tables pipeline in 'my_project/src': yes
Include a stub (sample) Python package in 'my_project/src': yes
Use serverless compute: yes
Workspace to use (auto-detected, edit in 'my_project/databricks.yml'): https://[workspace].databricks.com
✨ Your new project has been created in the 'my_project' directory!
Please refer to the README.md file for "getting started" instructions.
See also the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.
lennart:demo$ cd my_project
```
2. Run tests with `pytest`
```
lennart:my_project$ pytest
ImportError while loading conftest '/private/tmp/demp/my_project/conftest.py'.
conftest.py:17: in <module>
raise ImportError(
E ImportError: Test dependencies not found.
E
E Run tests using 'uv run pytest'. See http://docs.astral.sh/uv to learn move about uv.
```
3. Actually, Step 2 was wrong. Run tests using `uv`. Or from the VS Code
extension.
```
lennart:my_project$ uv run pytest
Using CPython 3.13.3 interpreter at: /opt/homebrew/opt/[email protected]/bin/python3.13
Creating virtual environment at: .venv
Built my-project @ file:///private/tmp/demo/my_project
Installed 32 packages in 235ms
☁️ no compute specified, falling back to serverless compute
see https://docs.databricks.com/dev-tools/databricks-connect/cluster-config for manual configuration
== test session starts ==
platform darwin -- Python 3.13.3, pytest-8.4.1, pluggy-1.6.0
rootdir: /private/tmp/demo/my_project
configfile: pyproject.toml
testpaths: tests
collected 1 item
tests/main_test.py . [100%]
== 1 passed in 1.71s ==
```
## Why
Manually setting up testing with DB Connect is still rather hard. With
these changes, uv can be used to setup testing automatically.
## Tests
* Acceptance tests
* Manual tests from CLI, Cursor, different versions of DB Connect
<!-- How have you tested the changes? -->
<!-- If your PR needs to be included in the release notes for next
release,
add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->1 parent 2035807 commit d19f143
File tree
26 files changed
+339
-158
lines changed- acceptance/bundle/templates/default-python
- classic/output/my_default_python
- scratch
- src
- my_default_python
- tests
- serverless/output/my_default_python
- scratch
- src
- my_default_python
- tests
- libs/template/templates/default-python
- library
- template/{{.project_name}}
- scratch
- src
- {{.project_name}}
- tests
26 files changed
+339
-158
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
Lines changed: 33 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
8 | 22 | | |
9 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
10 | 26 | | |
11 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
12 | 33 | | |
13 | 34 | | |
14 | 35 | | |
15 | 36 | | |
16 | | - | |
| 37 | + | |
17 | 38 | | |
18 | 39 | | |
19 | 40 | | |
| |||
23 | 44 | | |
24 | 45 | | |
25 | 46 | | |
26 | | - | |
| 47 | + | |
27 | 48 | | |
28 | | - | |
| 49 | + | |
29 | 50 | | |
30 | 51 | | |
31 | 52 | | |
| |||
35 | 56 | | |
36 | 57 | | |
37 | 58 | | |
38 | | - | |
| 59 | + | |
39 | 60 | | |
40 | 61 | | |
41 | 62 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
Lines changed: 6 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
25 | 19 | | |
26 | 20 | | |
27 | 21 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
Lines changed: 4 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | 9 | | |
21 | | - | |
| 10 | + | |
22 | 11 | | |
23 | 12 | | |
24 | 13 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
Lines changed: 33 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
8 | 22 | | |
9 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
10 | 26 | | |
11 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
12 | 33 | | |
13 | 34 | | |
14 | 35 | | |
15 | 36 | | |
16 | | - | |
| 37 | + | |
17 | 38 | | |
18 | 39 | | |
19 | 40 | | |
| |||
23 | 44 | | |
24 | 45 | | |
25 | 46 | | |
26 | | - | |
| 47 | + | |
27 | 48 | | |
28 | | - | |
| 49 | + | |
29 | 50 | | |
30 | 51 | | |
31 | 52 | | |
| |||
35 | 56 | | |
36 | 57 | | |
37 | 58 | | |
38 | | - | |
| 59 | + | |
39 | 60 | | |
40 | 61 | | |
41 | 62 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
0 commit comments