munit-cats-effect icon indicating copy to clipboard operation
munit-cats-effect copied to clipboard

ResourceSuiteLocalFixture is allocated after suite's beforeAll()

Open kamilkloch opened this issue 3 years ago • 5 comments

The following code

import cats.effect.IO
import cats.effect.kernel.Resource
import munit.CatsEffectSuite


class TestWsResource extends CatsEffectSuite {

  val d = ResourceSuiteLocalFixture(
    "Double resource",
    Resource.make(IO.println("Allocating resource") >> IO(4.0))(d => IO.println(s"Releasing resource: $d"))
  )

  override val munitFixtures = List(d)

  test("resource") {
    IO.println(s"Using resource: ${d()}")
  }

  override def beforeAll(): Unit = {
    // println(s"{${d()}")
    println(s"{d()}")
  }

  override def afterAll(): Unit = {
    println(s"After all ${d()}")
  }

}

produces

{{d()}
Allocating resource
Using resource: 4.0
After all 4.0
Releasing resource: 4.0

Changing beforeAll() to

  override def beforeAll(): Unit = {
    println(s"{${d()}")
  }

results in

Allocating resource
Releasing resource: 4.0

Process finished with exit code 255

munit.catseffect.ResourceFixture$FixtureNotInstantiatedException: The fixture `Double resource` was not instantiated. Override `munitFixtures` and include a reference to this fixture.

It looks that suite local resource is allocated after beforeAll and released after afterAll . Is this the desired behavior?

kamilkloch avatar Sep 07 '22 12:09 kamilkloch

Thanks for opening the issue. Which version is this? Can you replicate with the 2.x milestone? https://github.com/typelevel/munit-cats-effect/releases/tag/v2.0.0-M1

armanbilge avatar Sep 07 '22 14:09 armanbilge

Forgot to add: I am using v2.0.0-M1.

kamilkloch avatar Sep 07 '22 14:09 kamilkloch

Thanks for clarifying. Sorry, one more question: can you reproduce this without IO and munit-cats-effect? I have a hunch this is a question for munit itself.

See the docs here: https://github.com/scalameta/munit/blob/main/docs/fixtures.md#reusable-suite-local-fixtures

armanbilge avatar Sep 07 '22 14:09 armanbilge

@armanbilge It looks like the munit matter indeed: https://github.com/scalameta/munit/issues/573

kamilkloch avatar Sep 07 '22 15:09 kamilkloch

Can this issue be solved ? As the seen behaviour is the intended one ? ~But the linked munit issues (https://github.com/scalameta/munit/issues/573) is still open, too...~ it got closed in the meantime

mzuehlke avatar Apr 15 '24 11:04 mzuehlke