testenv

package
v1.104.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause Imports: 7 Imported by: 8 modules, 12 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testenv provides utility functions for tests. It does not depend on the `testing` package to allow usage in non-test code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertInTest added in v1.84.0

func AssertInTest()

AssertInTest panics if called outside of a test binary.

func InParallelTest added in v1.84.0

func InParallelTest(t TB) (isParallel bool)

InParallelTest reports whether t is running as a parallel test.

Use of this function taints t such that its Parallel method (assuming t is an actual *testing.T) will panic if called after this function.

func InSynctestBubble added in v1.104.0

func InSynctestBubble() bool

InSynctestBubble reports whether the current goroutine is running within a testing/synctest bubble.

As of Go 1.26 there is no public API to query bubble membership (internal/synctest.IsInBubble is runtime-internal), so this instead looks for the "synctest bubble N" annotation that the runtime renders in the current goroutine's runtime.Stack header. If a future Go release changes that annotation, this reports false; tests that depend on it for correctness (such as tailscale.com/util/zstdframe's) should exercise the misdetection failure mode so the breakage is loud.

func InTest

func InTest() bool

InTest reports whether the current binary is a test binary.

func Verbose added in v1.102.0

func Verbose() bool

Verbose reports whether the test binary is running with verbose output (the -test.v flag), like testing.Verbose but without importing the testing package.

Types

type TB added in v1.84.0

type TB interface {
	ArtifactDir() string
	Attr(key, value string)
	Cleanup(func())
	Error(args ...any)
	Errorf(format string, args ...any)
	Fail()
	FailNow()
	Failed() bool
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	Helper()
	Log(args ...any)
	Logf(format string, args ...any)
	Name() string
	Output() io.Writer
	Setenv(key, value string)
	Chdir(dir string)
	Skip(args ...any)
	SkipNow()
	Skipf(format string, args ...any)
	Skipped() bool
	TempDir() string
	Context() context.Context
}

TB is testing.TB, to avoid importing "testing" in non-test code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL