Skip to content

Commit 1aecf2b

Browse files
committed
Name pipelines test JUnit cases relative to the project folder, as pytest does
1 parent 557cdaa commit 1aecf2b

10 files changed

Lines changed: 47 additions & 38 deletions

File tree

‎acceptance/pipelines/test/results/out.failures.xml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
33
<testsuite name="my_pipeline" tests="4" failures="1" errors="1" skipped="1">
4-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_orders" name="test_valid_order" time="1.000"></testcase>
5-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_orders" name="test_backfill_fails" time="1.000">
4+
<testcase classname="tests.test_orders" name="test_valid_order" time="1.000"></testcase>
5+
<testcase classname="tests.test_orders" name="test_backfill_fails" time="1.000">
66
<failure message="AssertionError: assert 100 == 150">AssertionError: assert 100 == 150</failure>
77
</testcase>
8-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_orders" name="test_legacy_format_skipped" time="1.000">
8+
<testcase classname="tests.test_orders" name="test_legacy_format_skipped" time="1.000">
99
<skipped></skipped>
1010
</testcase>
11-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_orders" name="test_fixture_error" time="1.000">
11+
<testcase classname="tests.test_orders" name="test_fixture_error" time="1.000">
1212
<error message="RuntimeError: fixture &#39;orders&#39; setup failed">RuntimeError: fixture &#39;orders&#39; setup failed</error>
1313
</testcase>
1414
</testsuite>

‎acceptance/pipelines/test/results/out.incomplete.xml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
33
<testsuite name="my_pipeline" tests="4" failures="0" errors="3" skipped="0">
4-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_compute" name="test_small_order" time="1.000"></testcase>
5-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_compute" name="test_crash_on_large_order">
4+
<testcase classname="tests.test_compute" name="test_small_order" time="1.000"></testcase>
5+
<testcase classname="tests.test_compute" name="test_crash_on_large_order">
66
<error message="no result received"></error>
77
</testcase>
8-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_compute" name="test_last_order">
8+
<testcase classname="tests.test_compute" name="test_last_order">
99
<error message="no result received"></error>
1010
</testcase>
1111
<testcase name="update [UUID]">

‎acceptance/pipelines/test/results/out.late-failure.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
33
<testsuite name="my_pipeline" tests="3" failures="1" errors="1" skipped="0">
4-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_late_failure" name="test_backfill_fails" time="1.000">
4+
<testcase classname="tests.test_late_failure" name="test_backfill_fails" time="1.000">
55
<failure message="AssertionError: assert 100 == 150">AssertionError: assert 100 == 150</failure>
66
</testcase>
7-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_late_failure" name="test_breaks_update_after_summary" time="1.000"></testcase>
7+
<testcase classname="tests.test_late_failure" name="test_breaks_update_after_summary" time="1.000"></testcase>
88
<testcase name="update [UUID]">
99
<error message="update [UUID] is FAILED: ResultDeliveryException: Test results could not be verified.">update [UUID] is FAILED: ResultDeliveryException: Test results could not be verified.</error>
1010
</testcase>

‎acceptance/pipelines/test/results/out.update-failed.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
33
<testsuite name="my_pipeline" tests="2" failures="0" errors="1" skipped="0">
4-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-results.default.files.tests.test_delivery" name="test_breaks_update_after_summary" time="1.000"></testcase>
4+
<testcase classname="tests.test_delivery" name="test_breaks_update_after_summary" time="1.000"></testcase>
55
<testcase name="update [UUID]">
66
<error message="update [UUID] is FAILED: ResultDeliveryException: Test results could not be verified.">update [UUID] is FAILED: ResultDeliveryException: Test results could not be verified.</error>
77
</testcase>

‎acceptance/pipelines/test/run-control/out.resumed.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
33
<testsuite name="my_pipeline" tests="2" failures="0" errors="2" skipped="0">
4-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-run-control.default.files.tests.test_slow" name="test_hang_on_lock">
4+
<testcase classname="tests.test_slow" name="test_hang_on_lock">
55
<error message="no result received"></error>
66
</testcase>
77
<testcase name="update [UUID]">

‎acceptance/pipelines/test/run-control/output.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Error: stopped waiting for update [UUID] after 3s; the update keeps running, to
4444
<?xml version="1.0" encoding="UTF-8"?>
4545
<testsuites>
4646
<testsuite name="my_pipeline" tests="2" failures="0" errors="2" skipped="0">
47-
<testcase classname="Workspace.Users.[USERNAME]..bundle.test-pipeline-test-run-control.default.files.tests.test_slow" name="test_hang_on_lock">
47+
<testcase classname="tests.test_slow" name="test_hang_on_lock">
4848
<error message="no result received"></error>
4949
</testcase>
5050
<testcase name="update [UUID]">

‎cmd/pipelines/test.go‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ func bundleShortTestID(cwd, syncRoot, filesRoot, id string) string {
184184
return filepath.ToSlash(local) + testID
185185
}
186186

187-
// rootPathShortTestID shows a test ID whose path is under rootPath relative to it, which --pipeline-id
188-
// resolves against root_path to select the test again. Other test IDs are returned unchanged.
189-
func rootPathShortTestID(rootPath, id string) string {
190-
rel, testID, ok := cutTestIDFolder(rootPath, id)
187+
// relativeTestID shows a test ID whose path is under folder relative to it. Other test IDs are returned
188+
// unchanged. Relative to root_path, it is what --pipeline-id resolves to select the test again.
189+
func relativeTestID(folder, id string) string {
190+
rel, testID, ok := cutTestIDFolder(folder, id)
191191
if !ok {
192192
return id
193193
}
@@ -295,6 +295,9 @@ type testTarget struct {
295295
w *databricks.WorkspaceClient
296296
// shortID shows a test ID in the shortest form that selects the test again.
297297
shortID func(id string) string
298+
// projectFolder is the deployed folder that names test cases independently of the working
299+
// directory: the bundle's synchronized files, or root_path. It is "" when unknown.
300+
projectFolder string
298301
}
299302

300303
func (t testTarget) printHeader(out io.Writer, updateID string) {
@@ -327,8 +330,8 @@ func resolveTestTargetByID(cmd *cobra.Command, args []string, pipelineID string)
327330
if err != nil {
328331
return testTarget{}, err
329332
}
330-
shortID := func(id string) string { return rootPathShortTestID(rootPath, id) }
331-
return testTarget{pipelineID: pipelineID, selections: selections, w: w, shortID: shortID}, nil
333+
shortID := func(id string) string { return relativeTestID(rootPath, id) }
334+
return testTarget{pipelineID: pipelineID, selections: selections, w: w, shortID: shortID, projectFolder: rootPath}, nil
332335
}
333336

334337
// resolveTestTargetInBundle identifies the pipeline by its bundle KEY, which must precede any selections.
@@ -375,7 +378,7 @@ func resolveTestTargetInBundle(cmd *cobra.Command, args []string, resume bool) (
375378
return testTarget{}, err
376379
}
377380
shortID := func(id string) string { return bundleShortTestID(cwd, b.SyncRootPath, filesRoot, id) }
378-
return testTarget{key: key, pipelineID: pipelineID, selections: selections, w: b.WorkspaceClient(ctx), shortID: shortID}, nil
381+
return testTarget{key: key, pipelineID: pipelineID, selections: selections, w: b.WorkspaceClient(ctx), shortID: shortID, projectFolder: filesRoot}, nil
379382
}
380383

381384
// resumeCommand returns the command that reads the result of the update later.
@@ -629,6 +632,7 @@ names the cause.`,
629632
if report.suiteName == "" {
630633
report.suiteName = target.pipelineID
631634
}
635+
report.projectFolder = target.projectFolder
632636
// The CLI root doesn't cancel the context on signals, so stop waiting here.
633637
ctx, stop := signal.NotifyContext(cmd.Context(), os.Interrupt, syscall.SIGTERM)
634638
defer stop()

‎cmd/pipelines/test_junit.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ const junitNoResult = "no result received"
7373
// because CI tools treat skipped entries as passing.
7474
// A non-empty problem, such as an incomplete run, adds a failing entry for the update so the
7575
// report never passes by omission.
76-
func newJUnitReport(suiteName, updateID string, run *testRun, problem string) junitTestSuites {
76+
// Cases are named relative to projectFolder, as pytest names them, so that the names do not depend on
77+
// the working directory.
78+
func newJUnitReport(suiteName, updateID, projectFolder string, run *testRun, problem string) junitTestSuites {
7779
suite := junitTestSuite{Name: suiteName}
7880
for _, c := range run.cases {
7981
entry := junitTestCase{}
80-
entry.ClassName, entry.Name = junitCaseName(c.id)
82+
entry.ClassName, entry.Name = junitCaseName(relativeTestID(projectFolder, c.id))
8183
if d, ok := c.duration(); ok {
8284
entry.Time = fmt.Sprintf("%.3f", d.Seconds())
8385
}
@@ -120,9 +122,10 @@ func newJUnitReport(suiteName, updateID string, run *testRun, problem string) ju
120122

121123
// testReport writes the JUnit report of a test run to path, if --junit-xml is set.
122124
type testReport struct {
123-
path string
124-
out io.Writer
125-
suiteName string
125+
path string
126+
out io.Writer
127+
suiteName string
128+
projectFolder string
126129
}
127130

128131
// finish writes the report of a run that ended with runErr. A write error is joined with runErr,
@@ -131,7 +134,7 @@ func (r *testReport) finish(updateID string, run *testRun, problem string, runEr
131134
if r.path == "" {
132135
return runErr
133136
}
134-
if err := writeJUnitReport(r.path, newJUnitReport(r.suiteName, updateID, run, problem)); err != nil {
137+
if err := writeJUnitReport(r.path, newJUnitReport(r.suiteName, updateID, r.projectFolder, run, problem)); err != nil {
135138
if runErr == nil || errors.Is(runErr, root.ErrAlreadyPrinted) {
136139
return err
137140
}

‎cmd/pipelines/test_junit_test.go‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,26 @@ func TestJUnitCaseName(t *testing.T) {
3434
}
3535

3636
func TestWriteJUnitReport(t *testing.T) {
37+
// Cases are named relative to the project folder, as pytest names them, wherever the command runs.
38+
const project = "/Workspace/Users/someone/.bundle/orders/dev/files"
3739
run := newTestRun()
3840
for _, e := range []testPipelineEvent{
39-
caseEvent(t, "tests/test_a.py::test_ok", "RUNNING", "2026-01-01T00:00:00.000Z"),
40-
caseEvent(t, "tests/test_a.py::test_ok", "PASSED", "2026-01-01T00:00:01.840Z"),
41-
caseEvent(t, "tests/test_a.py::test_bad", "FAILED", "",
41+
caseEvent(t, project+"/tests/test_a.py::test_ok", "RUNNING", "2026-01-01T00:00:00.000Z"),
42+
caseEvent(t, project+"/tests/test_a.py::test_ok", "PASSED", "2026-01-01T00:00:01.840Z"),
43+
caseEvent(t, project+"/tests/test_a.py::test_bad", "FAILED", "",
4244
`"error": {"exceptions": [{"class_name": "AssertionError", "message": "assert 1 == 2\nwhere 1 = f()"}]}`,
4345
`"truncation": {"truncated_fields": [{"field_name": "error"}]}`),
44-
caseEvent(t, "tests/test_a.py::test_setup", "ERROR", "",
46+
caseEvent(t, project+"/tests/test_a.py::test_setup", "ERROR", "",
4547
`"error": {"exceptions": [{"class_name": "RuntimeError", "message": "fixture <db> failed"}]}`),
46-
caseEvent(t, "tests/test_a.py::test_old", "SKIPPED", ""),
47-
caseEvent(t, "tests/test_a.py::test_unfinished", "RUNNING", ""),
48+
caseEvent(t, project+"/tests/test_a.py::test_old", "SKIPPED", ""),
49+
caseEvent(t, project+"/tests/test_a.py::test_unfinished", "RUNNING", ""),
4850
} {
4951
run.add(e)
5052
}
5153

5254
path := filepath.Join(t.TempDir(), "report.xml")
5355
require.NoError(t, os.WriteFile(path, []byte("previous report"), 0o644))
54-
require.NoError(t, writeJUnitReport(path, newJUnitReport("orders", "u1", run, "RUN INCOMPLETE: received 4 of 5 test results.")))
56+
require.NoError(t, writeJUnitReport(path, newJUnitReport("orders", "u1", project, run, "RUN INCOMPLETE: received 4 of 5 test results.")))
5557

5658
data, err := os.ReadFile(path)
5759
require.NoError(t, err)

‎cmd/pipelines/test_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,20 @@ func TestBundleShortTestID(t *testing.T) {
126126
assert.Equal(t, id, bundleShortTestID(syncRoot, syncRoot, "", id))
127127
}
128128

129-
func TestRootPathShortTestID(t *testing.T) {
129+
func TestRelativeTestID(t *testing.T) {
130130
rootPath := "/Workspace/Users/someone/orders"
131-
assert.Equal(t, "tests/test_a.py::test_x", rootPathShortTestID(rootPath, rootPath+"/tests/test_a.py::test_x"))
132-
assert.Equal(t, "tests/test_a.py::test_x", rootPathShortTestID(rootPath+"/", rootPath+"/tests/test_a.py::test_x"))
131+
assert.Equal(t, "tests/test_a.py::test_x", relativeTestID(rootPath, rootPath+"/tests/test_a.py::test_x"))
132+
assert.Equal(t, "tests/test_a.py::test_x", relativeTestID(rootPath+"/", rootPath+"/tests/test_a.py::test_x"))
133133
// The service accepts workspace paths with or without the /Workspace prefix.
134-
assert.Equal(t, "tests/test_a.py::test_x", rootPathShortTestID("/Users/someone/orders", rootPath+"/tests/test_a.py::test_x"))
134+
assert.Equal(t, "tests/test_a.py::test_x", relativeTestID("/Users/someone/orders", rootPath+"/tests/test_a.py::test_x"))
135135
for _, other := range []string{
136136
"/Workspace/Users/someone/shared/test_s.py::test_s",
137137
rootPath + "2/test_a.py::test_x",
138138
"tests/test_a.py::test_x",
139139
} {
140-
assert.Equal(t, other, rootPathShortTestID(rootPath, other))
140+
assert.Equal(t, other, relativeTestID(rootPath, other))
141141
}
142-
assert.Equal(t, rootPath+"/tests/test_a.py::test_x", rootPathShortTestID("", rootPath+"/tests/test_a.py::test_x"))
142+
assert.Equal(t, rootPath+"/tests/test_a.py::test_x", relativeTestID("", rootPath+"/tests/test_a.py::test_x"))
143143
}
144144

145145
func TestRootPathSelection(t *testing.T) {

0 commit comments

Comments
 (0)