Skip to content

Commit 8edfc62

Browse files
tharunbhuk-dbIsaac
andcommitted
Merge the pipelines test command stack (#7297 to #7434) until it merges
Co-authored-by: Isaac <no-reply@databricks.com>
2 parents 3af4a58 + e358a5d commit 8edfc62

78 files changed

Lines changed: 3018 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎acceptance/pipelines/databricks-cli-help/output.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Main Commands
3030
run Run a pipeline
3131
show Preview a table's columns and sample rows
3232
stop Stop a pipeline
33+
test *Preview* Run the tests of a pipeline
3334

3435
Management Commands
3536
apply-environment *Public Preview* Apply the latest environment to the pipeline.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="1234" tests="1" failures="0" errors="1" skipped="0">
4+
<testcase name="pipelines test">
5+
<error message="unsupported pytest argument &#34;-x&#34;: only -k and -m are supported">unsupported pytest argument &#34;-x&#34;: only -k and -m are supported</error>
6+
</testcase>
7+
</testsuite>
8+
</testsuites>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="1234" tests="1" failures="0" errors="1" skipped="0">
4+
<testcase name="pipelines test">
5+
<error message="pipelines test is experimental. Set DATABRICKS_CLI_PIPELINES_TEST=true to enable it">pipelines test is experimental. Set DATABRICKS_CLI_PIPELINES_TEST=true to enable it</error>
6+
</testcase>
7+
</testsuite>
8+
</testsuites>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="1234" tests="1" failures="0" errors="1" skipped="0">
4+
<testcase name="pipelines test">
5+
<error message="--junit-xml cannot be used with --no-wait because no results are available when the command returns">--junit-xml cannot be used with --no-wait because no results are available when the command returns</error>
6+
</testcase>
7+
</testsuite>
8+
</testsuites>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cloud = false
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
>>> [CLI] pipelines test --help
3+
Run the tests of a pipeline in a test-only update.
4+
5+
This command is experimental. Set DATABRICKS_CLI_PIPELINES_TEST=true to enable it.
6+
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.
12+
13+
TEST_SELECTION is a test directory, file, or pytest test ID, for example
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
17+
pipeline's root_path. Paths that start with / are workspace paths. Without a
18+
selection, all of the pipeline's tests run.
19+
20+
Each --pytest-arg passes one argument to pytest, in the order given. Only -k
21+
and -m are supported, each followed by its value in the next --pytest-arg, for
22+
example:
23+
24+
databricks pipelines test my_pipeline --pytest-arg=-k --pytest-arg='orders and not slow'
25+
26+
The command waits for the results. It exits with code 0 only if at least one
27+
test was collected and none failed or errored, so a run whose tests were all
28+
skipped succeeds; otherwise it exits with code 1. --no-wait returns after the
29+
update starts.
30+
31+
--timeout and Ctrl+C stop waiting but not the update; pass its ID to --resume
32+
to read the results later. To stop the update, run 'pipelines stop'.
33+
34+
--junit-xml writes one entry per test with its outcome and duration. An
35+
incomplete run, a run without tests, or a timeout adds a failing entry that
36+
names the cause. The report replaces the file on every exit except a flag that
37+
cannot be parsed. With workspace.sync_mode immutable, test names keep the path
38+
of the deployed snapshot, which changes with each deployment.
39+
40+
Usage:
41+
databricks pipelines test [flags] [KEY] [TEST_SELECTION...]
42+
43+
Pipeline Test Flags:
44+
--junit-xml string Write the results as a JUnit XML report to this file, replacing it.
45+
--no-wait Don't wait for the tests to complete.
46+
--pipeline-id string ID of the pipeline to test, instead of a KEY.
47+
--pytest-arg stringArray Argument to pass to pytest (repeatable). Only -k and -m are supported.
48+
--resume string Read the results of an existing test update instead of starting one.
49+
--timeout duration Stop waiting for results after this duration, for example 30m. The update keeps running.
50+
51+
Flags:
52+
-h, --help help for test
53+
54+
Global Flags:
55+
--debug enable debug logging
56+
-o, --output type output type: text or json (default text)
57+
-p, --profile string ~/.databrickscfg profile
58+
-t, --target string bundle target to use (if applicable)
59+
--var strings set values for variables defined in project config. Example: --var="foo=bar"
60+
61+
=== The command is experimental and off by default
62+
>>> musterr [CLI] pipelines test --pipeline-id 1234
63+
Error: pipelines test is experimental. Set DATABRICKS_CLI_PIPELINES_TEST=true to enable it
64+
65+
=== With the command off, an older report is still replaced
66+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --junit-xml out.gate-off.xml
67+
Error: pipelines test is experimental. Set DATABRICKS_CLI_PIPELINES_TEST=true to enable it
68+
69+
=== pytest arguments must be passed with --pytest-arg
70+
>>> musterr [CLI] pipelines test --pipeline-id 1234 -k orders
71+
Error: -k is a pytest argument: pass pytest arguments with --pytest-arg, for example --pytest-arg=-k --pytest-arg='orders and not slow'
72+
73+
>>> musterr [CLI] pipelines test --pipeline-id 1234 -- -k orders
74+
Error: the -- separator is not supported: pass pytest arguments with --pytest-arg, for example --pytest-arg=-k --pytest-arg='orders and not slow'
75+
76+
=== Invalid --pytest-arg values fail before any request
77+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --pytest-arg=-x
78+
Error: unsupported pytest argument "-x": only -k and -m are supported
79+
80+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --pytest-arg=
81+
Error: --pytest-arg requires a non-empty value
82+
83+
=== The pipeline ID must be a pipeline ID
84+
>>> musterr [CLI] pipelines test --pipeline-id 1234
85+
Error: --pipeline-id "1234" is not a pipeline ID
86+
87+
=== JSON output is not supported
88+
>>> musterr [CLI] pipelines test --pipeline-id 1234 -o json
89+
Error: --output json is not supported by pipelines test
90+
91+
=== Incompatible run-control flags
92+
>>> musterr [CLI] pipelines test --pipeline-id 1234 tests --resume 5678
93+
Error: --resume cannot be used with test selections
94+
95+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --resume 5678 --pytest-arg=-m --pytest-arg=smoke
96+
Error: --resume cannot be used with --pytest-arg
97+
98+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --resume 5678 --no-wait
99+
Error: --resume cannot be used with --no-wait
100+
101+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --no-wait --timeout 10m
102+
Error: --timeout cannot be used with --no-wait
103+
104+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --resume 5678' OR '1'='1
105+
Error: --resume "5678' OR '1'='1" is not an update ID; pass the update ID that pipelines test printed
106+
107+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --resume
108+
Error: --resume "" is not an update ID; pass the update ID that pipelines test printed
109+
110+
=== --junit-xml needs the results
111+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --no-wait --junit-xml out.no-wait.xml
112+
Error: --junit-xml cannot be used with --no-wait because no results are available when the command returns
113+
114+
=== An invalid flag replaces an older report
115+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --pytest-arg=-x --junit-xml out.flag-error.xml
116+
Error: unsupported pytest argument "-x": only -k and -m are supported
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
trace $CLI pipelines test --help
2+
3+
title "The command is experimental and off by default"
4+
(unset DATABRICKS_CLI_PIPELINES_TEST; trace musterr $CLI pipelines test --pipeline-id 1234)
5+
6+
title "With the command off, an older report is still replaced"
7+
echo '<testsuites><testsuite name="old" tests="1"><testcase name="test_old"></testcase></testsuite></testsuites>' > out.gate-off.xml
8+
(unset DATABRICKS_CLI_PIPELINES_TEST; trace musterr $CLI pipelines test --pipeline-id 1234 --junit-xml out.gate-off.xml)
9+
10+
title "pytest arguments must be passed with --pytest-arg"
11+
trace musterr $CLI pipelines test --pipeline-id 1234 -k orders
12+
trace musterr $CLI pipelines test --pipeline-id 1234 -- -k orders
13+
14+
title "Invalid --pytest-arg values fail before any request"
15+
trace musterr $CLI pipelines test --pipeline-id 1234 --pytest-arg=-x
16+
trace musterr $CLI pipelines test --pipeline-id 1234 --pytest-arg=""
17+
18+
title "The pipeline ID must be a pipeline ID"
19+
trace musterr $CLI pipelines test --pipeline-id 1234
20+
21+
title "JSON output is not supported"
22+
trace musterr $CLI pipelines test --pipeline-id 1234 -o json
23+
24+
title "Incompatible run-control flags"
25+
trace musterr $CLI pipelines test --pipeline-id 1234 tests --resume 5678
26+
trace musterr $CLI pipelines test --pipeline-id 1234 --resume 5678 --pytest-arg=-m --pytest-arg=smoke
27+
trace musterr $CLI pipelines test --pipeline-id 1234 --resume 5678 --no-wait
28+
trace musterr $CLI pipelines test --pipeline-id 1234 --no-wait --timeout 10m
29+
trace musterr $CLI pipelines test --pipeline-id 1234 --resume "5678' OR '1'='1"
30+
trace musterr $CLI pipelines test --pipeline-id 1234 --resume ""
31+
32+
title "--junit-xml needs the results"
33+
trace musterr $CLI pipelines test --pipeline-id 1234 --no-wait --junit-xml out.no-wait.xml
34+
35+
title "An invalid flag replaces an older report"
36+
echo '<testsuites><testsuite name="old" tests="1"><testcase name="test_old"></testcase></testsuite></testsuites>' > out.flag-error.xml
37+
trace musterr $CLI pipelines test --pipeline-id 1234 --pytest-arg=-x --junit-xml out.flag-error.xml
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]?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 --no-wait
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])
24+
Update: [UUID]
25+
26+
>>> [CLI] pipelines test my_pipeline --no-wait
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])
32+
Update: [UUID]
33+
34+
>>> print_requests.py //updates
35+
{
36+
"method": "POST",
37+
"path": "/api/2.0/pipelines/[UUID]/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]/updates",
50+
"body": {
51+
"test_only": true
52+
}
53+
}

0 commit comments

Comments
 (0)