Skip to content

Commit ab02d65

Browse files
tharunbhuk-dbIsaac
andauthored
Run a bundle pipeline's tests by its KEY (#7431)
## 🥞 Stacked PR - [stack/pipelines-test-pr1-command](#7297) [[Files changed](https://github.com/databricks/cli/pull/7297/files)] - [**stack/pipelines-test-bundle-key**](#7431) [[Files changed](https://github.com/databricks/cli/pull/7431/files)] ← _this PR_ - [stack/pipelines-test-read-events](#7432) [[Files changed](https://github.com/databricks/cli/pull/7432/files)] - [stack/pipelines-test-print-results](#7433) [[Files changed](https://github.com/databricks/cli/pull/7433/files)] - [stack/pipelines-test-pr2-output](#7298) [[Files changed](https://github.com/databricks/cli/pull/7298/files)] - [stack/pipelines-test-a4-run-control](#7426) [[Files changed](https://github.com/databricks/cli/pull/7426/files)] - [stack/pipelines-test-pr3-junit](#7299) [[Files changed](https://github.com/databricks/cli/pull/7299/files)] - [stack/pipelines-test-junit-flag](#7434) [[Files changed](https://github.com/databricks/cli/pull/7434/files)] --------- - In a bundle, identify the pipeline by KEY: `pipelines test [flags] [KEY] [TEST_SELECTION...]`. - Relative selections are local paths, mapped to their deployed paths. - A first argument that is not a KEY gets an error that names the bundle's pipelines and the working command. Tests: unit tests; acceptance in `acceptance/pipelines/test/{selection,immutable}`. This pull request and its description were written by Isaac. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent b00fe63 commit ab02d65

17 files changed

Lines changed: 423 additions & 25 deletions

File tree

‎acceptance/pipelines/test/arguments/output.txt‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@ Run the tests of a pipeline in a test-only update.
44

55
This command is experimental. Set DATABRICKS_CLI_PIPELINES_TEST=true to enable it.
66

7-
Identify the pipeline with --pipeline-id.
7+
KEY is the unique name of the pipeline, as defined in its YAML file.
8+
It is required when test selections are given. If there is only one pipeline
9+
in the project and no arguments are given, it is selected automatically.
10+
Outside a project, identify the pipeline with --pipeline-id; all positional
11+
arguments are then test selections.
812

913
TEST_SELECTION is a test directory, file, or pytest test ID, for example
10-
tests/test_orders.py::test_backfill. A relative path is relative to the
14+
tests/test_orders.py::test_backfill. In a project, a relative path is a local
15+
path, relative to the working directory, and is converted to its deployed
16+
workspace path. With --pipeline-id, a relative path is relative to the
1117
pipeline's root_path. Paths that start with / are workspace paths. Without a
1218
selection, all of the pipeline's tests run.
1319

1420
Each --pytest-arg passes one argument to pytest, in the order given. Only -k
1521
and -m are supported, each followed by its value in the next --pytest-arg, for
1622
example:
1723

18-
databricks pipelines test --pipeline-id <id> --pytest-arg=-k --pytest-arg='orders and not slow'
24+
databricks pipelines test my_pipeline --pytest-arg=-k --pytest-arg='orders and not slow'
1925

2026
Usage:
21-
databricks pipelines test [flags] [TEST_SELECTION...]
27+
databricks pipelines test [flags] [KEY] [TEST_SELECTION...]
2228

2329
Pipeline Test Flags:
24-
--pipeline-id string ID of the pipeline to test.
30+
--pipeline-id string ID of the pipeline to test, instead of a KEY.
2531
--pytest-arg stringArray Argument to pass to pytest (repeatable). Only -k and -m are supported.
2632

2733
Flags:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bundle:
2+
name: test-pipeline-test-immutable
3+
4+
workspace:
5+
sync_mode: immutable
6+
7+
resources:
8+
pipelines:
9+
my_pipeline:
10+
name: test-pipeline-test-immutable
11+
libraries:
12+
- file:
13+
path: pipeline_file.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cloud = false
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
>>> [CLI] pipelines deploy
3+
Created internal_immutable_snapshots.immutable
4+
Created pipelines.my_pipeline
5+
Files: 0 uploaded, 0 deleted
6+
Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
7+
View your pipeline my_pipeline here: [DATABRICKS_URL]/pipelines/[UUID][0]?w=[WORKSPACE_ID]
8+
9+
=== Local test paths are not supported with workspace.sync_mode immutable
10+
>>> musterr [CLI] pipelines test my_pipeline tests/test_orders.py::test_backfill
11+
Recommendation: This command runs the last deployed version of the code
12+
13+
If you've made local changes, run 'databricks pipelines deploy' first to ensure they are included.
14+
15+
Error: cannot resolve test selection "tests/test_orders.py::test_backfill": local test paths are not supported with workspace.sync_mode immutable; pass an absolute workspace path
16+
17+
=== Absolute workspace paths and running all tests still work
18+
>>> MSYS_NO_PATHCONV=1 [CLI] pipelines test my_pipeline /Workspace/Users/someone@example.com/tests/test_orders.py::test_backfill
19+
Recommendation: This command runs the last deployed version of the code
20+
21+
If you've made local changes, run 'databricks pipelines deploy' first to ensure they are included.
22+
23+
Pipeline: my_pipeline ([UUID][0])
24+
Update: [UUID][1]
25+
26+
>>> [CLI] pipelines test my_pipeline
27+
Recommendation: This command runs the last deployed version of the code
28+
29+
If you've made local changes, run 'databricks pipelines deploy' first to ensure they are included.
30+
31+
Pipeline: my_pipeline ([UUID][0])
32+
Update: [UUID][2]
33+
34+
>>> print_requests.py //updates
35+
{
36+
"method": "POST",
37+
"path": "/api/2.0/pipelines/[UUID][0]/updates",
38+
"body": {
39+
"test_only": true,
40+
"test_options": {
41+
"test_selection": [
42+
"/Workspace/Users/someone@example.com/tests/test_orders.py::test_backfill"
43+
]
44+
}
45+
}
46+
}
47+
{
48+
"method": "POST",
49+
"path": "/api/2.0/pipelines/[UUID][0]/updates",
50+
"body": {
51+
"test_only": true
52+
}
53+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pyspark import pipelines as dp
2+
3+
4+
@dp.table
5+
def orders():
6+
return spark.range(10)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trace $CLI pipelines deploy
2+
rm "$OUT_REQUESTS"
3+
4+
title "Local test paths are not supported with workspace.sync_mode immutable"
5+
trace musterr $CLI pipelines test my_pipeline tests/test_orders.py::test_backfill
6+
7+
title "Absolute workspace paths and running all tests still work"
8+
trace MSYS_NO_PATHCONV=1 $CLI pipelines test my_pipeline /Workspace/Users/someone@example.com/tests/test_orders.py::test_backfill
9+
trace $CLI pipelines test my_pipeline
10+
trace print_requests.py //updates
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_backfill():
2+
assert True

‎acceptance/pipelines/test/pipeline-id/output.txt‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Update: [UUID][3]
4141
}
4242
}
4343

44-
=== --pipeline-id is required
44+
=== Outside a project, --pipeline-id is required
4545
>>> musterr [CLI] pipelines test tests
46-
Error: identify the pipeline with --pipeline-id
46+
Error: Unable to locate the bundle root: databricks.yml not found.
47+
48+
Run this command from a directory that contains a bundle, or set the DATABRICKS_BUNDLE_ROOT environment variable to the bundle root directory.
49+
Alternatively, create a new bundle with 'databricks bundle init'.
50+

‎acceptance/pipelines/test/pipeline-id/script‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ trace musterr $CLI pipelines test --pipeline-id $no_root_pipeline_id tests
1111
trace MSYS_NO_PATHCONV=1 $CLI pipelines test --pipeline-id $no_root_pipeline_id /Workspace/Users/someone@example.com/tests/test_other.py::test_x
1212
trace print_requests.py //updates
1313

14-
title "--pipeline-id is required"
14+
title "Outside a project, --pipeline-id is required"
1515
trace musterr $CLI pipelines test tests
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bundle:
2+
name: test-pipeline-test-selection
3+
4+
resources:
5+
pipelines:
6+
my_pipeline:
7+
name: test-pipeline-test-selection
8+
libraries:
9+
- file:
10+
path: pipeline_file.py

0 commit comments

Comments
 (0)