Feature
Package testoreflect provides FuncPC uintptr field with program counter of a function which defines either regular test or parametrized test.
With it, we can obtain file and line of such tests
pc := testo.Reflect(t).Test.(testoreflect.RegularTestInfo).FuncPC
f := runtime.FuncForPC(pc)
fmt.Println(f.FileLine(pc))
However, it is only available for top-level tests and is equal to 0 for tests started with testo.Run (sub-tests).
See runner.go file for definition of testo.Run.
Usage example (won't work without this feature):
func (Suite) Test(t T) {
testo.Run(t, "my subtest", func(t T) {
pc := testo.Reflect(t).Test.(testoreflect.RegularTestInfo).FuncPC
f := runtime.FuncForPC(pc)
fmt.Println(f.FileLine(pc))
})
testo.Run(t, "predefined", someFunc)
}
func someFunc(t T) {
pc := testo.Reflect(t).Test.(testoreflect.RegularTestInfo).FuncPC
f := runtime.FuncForPC(pc)
fmt.Println(f.FileLine(pc))
}
Feature
Package
testoreflectprovidesFuncPC uintptrfield with program counter of a function which defines either regular test or parametrized test.With it, we can obtain file and line of such tests
However, it is only available for top-level tests and is equal to 0 for tests started with
testo.Run(sub-tests).See
runner.gofile for definition oftesto.Run.Usage example (won't work without this feature):