Skip to content
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

ResourceSuiteLocalFixture is allocated after suite's beforeAll() #234

Open
kamilkloch opened this issue Sep 7, 2022 · 5 comments
Open

Comments

@kamilkloch
Copy link

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?

@armanbilge
Copy link
Member

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

@kamilkloch
Copy link
Author

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

@armanbilge
Copy link
Member

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

@kamilkloch
Copy link
Author

@armanbilge It looks like the munit matter indeed: scalameta/munit#573

@mzuehlke
Copy link
Contributor

mzuehlke commented Apr 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants