kotest icon indicating copy to clipboard operation
kotest copied to clipboard

Support nested isolation mode per describe

Open maxime1992 opened this issue 2 years ago • 4 comments

Hello, I'm just getting started with Kotest and Kotlin in general.

I struggled with a test recently because I misunderstood how IsolationMode works. I thought I could do something like this

class SomeTest : DescribeSpec({
  // default isolation mode: same for all the tests in the class
  // we can make expensive setup here like booting a docker container

  describe("Describe 1") {
    isolationMode = IsolationMode.InstancePerLeaf

    // some cheap setup that we can clear for each test *of the current scope, the current describe*
    // and variables that should be independant per test for the current describe

    it("Test 1") { ... }

    it("Test 2") { ... }
  }
}

Except that with the above example, there's no errors but the isolation mode per leaf is not applied. Which means I had my tests running but the variables defined in the describe where not independant. It was particularly confusing as I ran my tests one by one as I was writing them, and at the end when I try to run them all at once, it failed.

I think it'd be nice to be able to describe the isolation mode per describe instead of per class.

It wouldn't even be a breaking change as currently it only supports isolation mode to be set at the top, not in nested describe.

maxime1992 avatar May 05 '23 12:05 maxime1992

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '23 06:08 stale[bot]

Up

maxime1992 avatar Aug 12 '23 18:08 maxime1992

It would be incredibly cool to change isolation mode per container to e.g. share container state across the inner tests

almozavr avatar Aug 18 '23 12:08 almozavr

This would be neat but I fear the implementation would be very complex. It's already tricky enough to support the three isolation modes just at the top level.

sksamuel avatar Aug 28 '23 01:08 sksamuel

Going to close because implementation of this is too complicated with edgecases.

sksamuel avatar Mar 10 '24 19:03 sksamuel