Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign uptesting: add -failfast to stop after first test failure #21700
Comments
cespare
added
the
Proposal
label
Aug 30, 2017
gopherbot
added this to the Proposal milestone
Aug 30, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
AlexRouSg
Aug 31, 2017
Contributor
You could have a single test function and use subtests and then check if one failed and don't run the rest.
func TestFoo(t *testing.T) {
failed := false
if !failed {
t.Run("A=1", func(t *testing.T) { failed = true })
}
if !failed {
t.Run("A=2", func(t *testing.T) { failed = true })
}
if !failed {
t.Run("A=3", func(t *testing.T) { failed = true })
}
}
|
You could have a single test function and use subtests and then check if one failed and don't run the rest.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
cespare
Sep 6, 2017
Contributor
@AlexRouSg sure, or I can comment out all the other tests. This proposal is about a way to improve the use cases I mentioned without restructuring the code.
|
@AlexRouSg sure, or I can comment out all the other tests. This proposal is about a way to improve the use cases I mentioned without restructuring the code. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
This seems OK but we have to come up with a decent flag name. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
spf13
Oct 16, 2017
Contributor
In a few other similar tools the flag used is "--failfast"
- Django
- Rspec
|
In a few other similar tools the flag used is "--failfast"
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Others that come to mind are |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rsc
Oct 20, 2017
Contributor
Let's use -(test.)failfast. If anyone wants to send a CL, please go ahead. (Remember to write a test and run mkalldocs.sh.) Thanks.
|
Let's use -(test.)failfast. If anyone wants to send a CL, please go ahead. (Remember to write a test and run mkalldocs.sh.) Thanks. |
rsc
added
the
Proposal-Accepted
label
Oct 20, 2017
rsc
modified the milestones:
Proposal,
Go1.10
Oct 20, 2017
rsc
changed the title from
proposal: testing: add a flag to exit after the first test failure
to
testing: add -failfast to stop after first test failure
Oct 20, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
gopherbot
Oct 30, 2017
Change https://golang.org/cl/74450 mentions this issue: testing: add -failfast to stop after first test failure
gopherbot
commented
Oct 30, 2017
|
Change https://golang.org/cl/74450 mentions this issue: |
gopherbot
closed this
in
153e409
Nov 29, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
inancgumus
Nov 29, 2017
Contributor
I completed my work on this. Currently, it tries to stop the tests from running. However, with parallel tests, this isn't easy to do right now (I guess).
|
I completed my work on this. Currently, it tries to stop the tests from running. However, with parallel tests, this isn't easy to do right now (I guess). |
cespare commentedAug 30, 2017
I propose we add a testing flag to cause
go testto exit after the first test failure.There are two cases where I've wanted such a flag:
-count 10000for this purpose, but it will keep running the test after it fails once, so if I'm not looking at my terminal while it's running I need to go hunt through my scrollback to locate the failure. (Alternatively, I can usego test -cand re-run the test until failure using my shell, but this is slower, particularly if there's some kind of setup in a TestMain.)-runto select it, but then once I've fixed that failure I want to focus the next one so I need to run all the tests again and repeat the process. It would be more convenient to rungo test -exit1(need a better flag name).In the presence of t.Parallel this gets a little trickier. I suggest handling it by collecting the parallel results as they arrive and then exiting after the first failure, printing only the results that came in before the failure and then the failure last, but not printing results that arrived after the failure. The main subtlety for the user is that they might see output logged from other parallel tests which don't have success/failure printouts, but that seems like a minor concern.