ginkgo icon indicating copy to clipboard operation
ginkgo copied to clipboard

How to programmatically stop Ginkgo execution on test failure?

Open marten-seemann opened this issue 5 years ago • 5 comments

I'm looking for a way to programmatically stop the execution of a test run if a certain assertion fails. Background: It's an assertion I'm running in an AfterEach, and I know that if it fails once, it will definitely fail on all subsequent executions.

Note that this more nuanced than running ginkgo with -failFast, as it's only one particular failure that will cause this behavior.

marten-seemann avatar Nov 06 '20 06:11 marten-seemann

I guess you could do something like:

var bailOut bool

BeforeEach(func() {
  if bailOut {
    Skip("bailing out")
  }
})

AfterEach(func() {
  if badThingHappened() {
    bailOut = true
  }
})

blgm avatar Nov 06 '20 10:11 blgm

That would work, but pollute all my output with Skipped messages. I was wondering if you'd consider exposing a StopTestRun() method or so.

marten-seemann avatar Nov 07 '20 03:11 marten-seemann

I think that's a good feature request. At the moment @onsi is working on Ginko 2.0 which will have more sophisticated control over test execution. It might make sense to add it as part of that work.

blgm avatar Nov 07 '20 13:11 blgm

The feature request makes sense to me - the tricky bit is orchestration when running in parallel. One node will need to signal to all other nodes to shut down. Not at all impossible, but the only reason that this isn't straightforward. I'll add it to the 2.0 list.

onsi avatar Nov 07 '20 14:11 onsi

V2 now provides AbortSuite which solves for this use case. It works when running in series or in parallel and will immediately end test execution. V2 is in beta now and I'd love for folks to use it and send me feedback. Docs for using the beta are here.

onsi avatar Sep 30 '21 03:09 onsi