Skip to content

Commit 878826c

Browse files
authored
acc: add ability to skip tests dynamically (#2894)
## Changes - If acceptance test outputs "SKIP_TEST <reason>" as last line, test runner will call t.Skip() on this test. - Modify "Summary" output to indicate that this about directories, not test cases (single directory can expand to many test cases; dynamic skips are not reflected in the output of Summary line). ## Why See #2876 -- we test all combinations of default-python template there but not all of them work in all environments. ## Tests New selftest. Testing in practice in #2876
1 parent 01e2053 commit 878826c

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

acceptance/acceptance_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
257257
})
258258
}
259259

260-
t.Logf("Summary: %d/%d/%d run/selected/total, %d skipped", selectedDirs-skippedDirs, selectedDirs, totalDirs, skippedDirs)
260+
t.Logf("Summary (dirs): %d/%d/%d run/selected/total, %d skipped", selectedDirs-skippedDirs, selectedDirs, totalDirs, skippedDirs)
261261

262262
return len(testDirs)
263263
}
@@ -471,7 +471,11 @@ func runTest(t *testing.T,
471471
require.NoError(t, err)
472472
defer out.Close()
473473

474-
err = runWithLog(t, cmd, out, tailOutput)
474+
skipReason, err := runWithLog(t, cmd, out, tailOutput)
475+
476+
if skipReason != "" {
477+
t.Skip("Skipping based on output: " + skipReason)
478+
}
475479

476480
// Include exit code in output (if non-zero)
477481
formatOutput(out, err)
@@ -847,7 +851,7 @@ func isTruePtr(value *bool) bool {
847851
return value != nil && *value
848852
}
849853

850-
func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) error {
854+
func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) (string, error) {
851855
r, w := io.Pipe()
852856
cmd.Stdout = w
853857
cmd.Stderr = w
@@ -863,14 +867,16 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) error {
863867
start := time.Now()
864868
err := cmd.Start()
865869
if err != nil {
866-
return err
870+
return "", err
867871
}
868872

869873
go func() {
870874
processErrCh <- cmd.Wait()
871875
_ = w.Close()
872876
}()
873877

878+
mostRecentLine := ""
879+
874880
reader := bufio.NewReader(r)
875881
for {
876882
line, err := reader.ReadString('\n')
@@ -882,6 +888,7 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) error {
882888
}
883889
}
884890
if len(line) > 0 {
891+
mostRecentLine = line
885892
_, err = out.WriteString(line)
886893
require.NoError(t, err)
887894
}
@@ -891,7 +898,13 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) error {
891898
require.NoError(t, err)
892899
}
893900

894-
return <-processErrCh
901+
mostRecentLine = strings.TrimRight(mostRecentLine, "\n")
902+
skipReason := ""
903+
if strings.HasPrefix(mostRecentLine, "SKIP_TEST") {
904+
skipReason = mostRecentLine
905+
}
906+
907+
return skipReason, <-processErrCh
895908
}
896909

897910
func getCloudEnvBase(cloudEnv string) string {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output.txt will not be checked for skipped test

acceptance/selftest/skip/script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo SKIP_TEST testing skip functionality

0 commit comments

Comments
 (0)