stretchr/testify · info

YAML functions are not available (see https://pkg.go.dev/git

Error message

YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)

What it means

This is the entire payload of the testify_yaml_fail build-tag implementation (assert/yaml/yaml_fail.go). When the module is compiled with -tags testify_yaml_fail, the yaml subpackage is replaced by a stub whose Unmarshal always returns this error. It is a deliberate opt-in to exclude gopkg.in/yaml.v3 from the build (e.g. to satisfy license policy or reduce binary size). It is NOT a runtime defect.

Source

Thrown at assert/yaml/yaml_fail.go:13

//go:build testify_yaml_fail && !testify_yaml_custom && !testify_yaml_default

// Package yaml is an implementation of YAML functions that always fail.
//
// This implementation can be used at build time to replace the default implementation
// to avoid linking with [gopkg.in/yaml.v3]:
//
//	go test -tags testify_yaml_fail
package yaml

import "errors"

var errNotImplemented = errors.New("YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)")

func Unmarshal([]byte, interface{}) error {
	return errNotImplemented
}

View on GitHub (pinned to 001eb7946b)

Solutions

  1. If you need YAML assertions, remove the testify_yaml_fail build tag (or switch to testify_yaml_default / testify_yaml_custom).
  2. If you must keep the fail tag, replace YAMLEq assertions with JSON-based equivalents (assert.JSONEq).
  3. Provide a custom YAML implementation by building with -tags testify_yaml_custom and registering your own unmarshaller.

Example fix

// before: run with -tags testify_yaml_fail
//   assert.YAMLEq(t, yamlStr, got)
// after: drop the tag, or use JSON
//   assert.JSONEq(t, jsonStr, got)
Defensive patterns

Strategy: validation

Validate before calling

// At startup of test files using YAML, fail fast with a clear message:
var _ = func() bool {
    err := yaml.Unmarshal([]byte("{}"), &map[string]interface{}{})
    if err != nil && err.Error() == "YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)" {
        log.Println("testify built with testify_yaml_fail; YAMLEq unavailable")
    }
    return true
}()

Type guard

// Runtime feature probe:
func yamlAvailable() bool {
    var m map[string]interface{}
    return yaml.Unmarshal([]byte("{}"), &m) == nil
}

Try / catch

// Branch on availability rather than crashing the suite:
if !yamlAvailable() {
    t.Skip("YAML assertions disabled in this build")
}
assert.YAMLEq(t, want, got)

Prevention

When it happens

Trigger: Running tests with `go test -tags testify_yaml_fail` and then calling any assert function that needs YAML (assert.YAMLEq, assert.YAMLEqMap, or objects whose Diff rendering falls back to YAML). The fail-tag stub's Unmarshal returns errNotImplemented unconditionally.

Common situations: A CI pipeline or Dockerfile adds the testify_yaml_fail tag globally (via GOFLAGS or Makefile), then a new test starts using YAMLEq. Also happens when a project's build tags were copied from a template without understanding them.


AI-assisted analysis of stretchr/testify@001eb7946b (2026-08-04). Data as JSON: /data/errors/f4c9712b0ae98d8b.json. Report an issue: GitHub.