Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: testing: export test/benchmark name #16901

Closed
RaduBerinde opened this issue Aug 27, 2016 · 4 comments

Comments

Projects
None yet
5 participants
@RaduBerinde
Copy link
Contributor

commented Aug 27, 2016

This is a proposal to add a Name() string function to testing.TB that returns the name of the test/benchmark. This is necessary to differentiate between debugging messages, events, traces etc when running tests/benchmarks in parallel.

In many cases one can figure out the enclosing Test.. function by studying the caller stack but that wouldn't work for subtests. This feature would be especially useful when the subtests are generated programatically, e.g. for i := 1; i <= 5; i++ { t.Run(fmt.Sprintf("i=%d", i), ..)

@josharian

This comment has been minimized.

Copy link
Contributor

commented Aug 27, 2016

Interesting. Somewhat related: #4899. cc @adg @mpvl @robpike

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Sep 6, 2016

I feel like this is solving the wrong problem; the TB already knows which subtest it is for, maybe the log output should just be changed to prepend every log message with the name of the test?

Also the hypothetical JSON output (#2981) separates log messages by test.

@quentinmit quentinmit added this to the Go1.8Maybe milestone Sep 6, 2016

@RaduBerinde

This comment has been minimized.

Copy link
Contributor Author

commented Sep 6, 2016

That is only helpful for logs that go through TB. Tests might spin up non-testing machinery which can have its own internal methods for outputting debug messages. Plus this is not limited to printed logs, it could be used for other things like traces (e.g. LightStep).

RaduBerinde referenced this issue in RaduBerinde/cockroach Oct 1, 2016

@adg

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2016

Fixed in #17231.

@adg adg closed this Oct 3, 2016

@golang golang locked and limited conversation to collaborators Oct 3, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.