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
Closed

proposal: testing: export test/benchmark name #16901

RaduBerinde opened this issue Aug 27, 2016 · 4 comments

Comments

@RaduBerinde
Copy link
Contributor

RaduBerinde 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
Copy link
Contributor

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

@quentinmit
Copy link
Contributor

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
Copy link
Contributor Author

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).

@adg
Copy link
Contributor

adg commented Oct 3, 2016

Fixed in #17231.

@adg adg closed this as completed 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.
Projects
None yet
Development

No branches or pull requests

5 participants