Skip to content

proposal: testing: add Count function to return the test.count value #64883

@purpleidea

Description

@purpleidea

Proposal Details

In golang 1.21.0 a new Testing function was added to the "testing" package. I propose a similar and new Count function which along the same lines, returns the test.count value for the test. Implementation is similar to Short shown here:

// Short reports whether the -test.short flag is set.
func Short() bool {
	if short == nil {
		panic("testing: Short called before Init")
	}
	// Catch code that calls this from TestMain without first calling flag.Parse.
	if !flag.Parsed() {
		panic("testing: Short called before Parse")
	}

	return *short
}

This would be very useful to allow a test to perform some more expensive global setup only once if it's going to be run multiple times, for example. Or to know how much longer we expect a test to last. (Eg: time*count)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions