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
Could you explain on why t.Cleanup
is required over defer
in some situations?
#23
Comments
I was curious too, so this is for future Googlers. The README says that this tool was inspired by a blog post: Go 言語でのテストの並列化 〜t.Parallel()メソッドを理解する〜. I used Google Translate to get the following translation of the last section, which is helpfully labeled "
|
Ah, thanks for tracking that down @telemachus. I'm going to add a couple snippets from the blog post here as well for easier reference. The implementation of func Test_Func1(t *testing.T) {
defer trace("Test_Func1")()
t.Run("Func1_Sub1", func(t *testing.T) {
defer trace("Func1_Sub1")()
t.Parallel()
// ...
})
t.Run("Func1_Sub2", func(t *testing.T) {
defer trace("Func1_Sub2")()
t.Parallel()
// ...
})
// ...
} And a sample run where you can see the top-level
If I had to summarize the problem: use of |
tparallel
will require the use oft.Cleanup
instead ofdefer
in cases where a top-level test case has subtests, and that top-level test case ist.Parallel
. From the README:I was bringing
t.Parallel
into a project and had to make some changes related to this, but was having a hard time explaining to my colleague why exactly those changes are necessary.Could you elaborate a little more on why exactly
t.Cleanup
needs to be used instead ofdefer
in some cases? I can help expand the README to explain it if you'd like (after I understand it myself that is).The text was updated successfully, but these errors were encountered: