GoogleContainerTools/skaffold · error

failed to test: %w

Error message

failed to test: %w

What it means

After a successful build, `skaffold run` executes the test suite defined in the test section via `r.Test`; this wrapper reports a test failure and stops the run before deploy. It means one of the configured image/container-structure tests or custom test runners returned a non-zero result.

Source

Thrown at cmd/skaffold/app/cmd/run.go:54

		WithLongDescription("Run a pipeline: build and test artifacts, tag them, update Kubernetes manifests and deploy to a cluster.").
		WithExample("Build, test, deploy and tail the logs", "run --tail").
		WithExample("Run with a given profile", "run -p <profile>").
		WithCommonFlags().
		WithHouseKeepingMessages().
		NoArgs(doRun)
}

func doRun(ctx context.Context, out io.Writer) error {
	return withRunner(ctx, out, func(r runner.Runner, configs []util.VersionedConfig) error {
		bRes, err := r.Build(ctx, out, targetArtifacts(opts, configs))
		if err != nil {
			return fmt.Errorf("failed to build: %w", err)
		}

		if !opts.SkipTests {
			err = r.Test(ctx, out, bRes)
			if err != nil {
				return fmt.Errorf("failed to test: %w", err)
			}
		}

		// Render
		manifestList, err := r.Render(ctx, out, bRes, false)
		if err != nil {
			return fmt.Errorf("rendering manifests: %w", err)
		}
		if opts.RenderOnly {
			return manifest.Write(manifestList.String(), opts.RenderOutput, out)
		}

		err = r.DeployAndLog(ctx, out, bRes, manifestList)
		if err != nil {
			return fmt.Errorf("failed to deploy: %w", err)
		}

		tips.PrintForRun(out, opts)

View on GitHub (pinned to a1189de023)

Solutions

  1. Read the wrapped test output to identify which test suite failed and why.
  2. Reproduce locally with `skaffold test` (or `skaffold run --skip-tests` to isolate) and fix the failing test or the code it covers.
  3. If tests are intentionally skipped in this context, run `skaffold run --skip-tests`.
  4. Rebuild test images / clear stale cache so tests run against current code: `skaffold build --profile <test-profile>` then run.

Example fix

# before: run fails on failing tests
skaffold run
# after: intentionally bypass tests (or fix them first)
skaffold run --skip-tests
# or, to debug:
skaffold test
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure test prerequisites exist before skaffold run
const cfg = require('js-yaml').load(require('fs').readFileSync('skaffold.yaml', 'utf8'));
const hasTests = Array.isArray(cfg.test) && cfg.test.length > 0;
const skip = process.env.SKIP_TESTS === 'true';
if (hasTests && !skip) {
  // run tests alone first so failures don't abort run mid-pipeline
  execFileSync('skaffold', ['test'], {stdio: 'inherit'});
}

Try / catch

try {
  execFileSync('skaffold', ['run'], {stdio: 'pipe'});
} catch (e) {
  const msg = e.stderr?.toString() ?? '';
  if (msg.includes('failed to test')) {
    console.error('skaffold run aborted at test stage; run `skaffold test` to see failing suites:', msg);
    // fallback for non-blocking pipelines:
    // execFileSync('skaffold', ['run', '--skip-tests']);
  } else throw e;
}

Prevention

When it happens

Trigger: `skaffold run` (without --skip-tests) where a test in the skaffold.yaml test section fails: container-structure-test failures, custom test command exits non-zero, test image missing, or the test harness can't start (e.g. docker unavailable).

Common situations: A recently changed application breaks container-structure-test assertions; custom test scripts depend on files/env vars absent in CI; test image wasn't rebuilt after dependency changes; flaky tests failing in CI only.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/ba7588b6ad8598e2. Report an issue: GitHub.