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

Use of "withEnvironment" extension function works when playing a spec class, but not an individual leaf #250

Closed
zakhenry opened this issue Apr 16, 2023 · 5 comments

Comments

@zakhenry
Copy link

for example with the following spec file:

/* 1 ▷ */ class FTest: DescribeSpec({

/* 2 ▷ */    describe("f") {

/* 3 ▷ */        it("f") {

                     withEnvironment("FooKey", "BarValue") {
                         System.getenv("FooKey") shouldBe "BarValue" // System environment overridden!
                     }

                 }

             }

         })

if I play the line 1 the test passes, however if I play 2 or 3 the test fails with

Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @4f209819
java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @4f209819

Kotest 5.5.2 and plugin version 1.3.68-IC-2023.1. I do have the following lines in build.gradle.kts

tasks.withType<Test>().configureEach {
    jvmArgs("--add-opens=java.base/java.util=ALL-UNNAMED")
}
@Kantis
Copy link
Member

Kantis commented Apr 21, 2023

@zakhenry the Gradle configuration will only take effect when tests are invoked using Gradle.

When running an individual test, Kotest IntelliJ plugin will not invoke the test with Gradle, so the --add-opens is not applied.

Once #178 is fixed, you could configure IntelliJ to run tests with Gradle and this would work for individual tests as well.

@sksamuel
Copy link
Member

sksamuel commented Apr 21, 2023 via email

@zakhenry
Copy link
Author

zakhenry commented May 1, 2023

Ah yes this is a good solution thanks, doc ref for future reference: https://kotest.io/docs/intellij/intellij-properties.html

@zakhenry zakhenry closed this as completed May 1, 2023
@sgc109
Copy link

sgc109 commented May 26, 2024

'withEnvironment' still doesn't work in kotest 5.5.5.
I've opened the issue kotest/kotest#4036

@florianmutter
Copy link

Could someone add an example what we need to put into kotest.properties to get withEnvironment {} working?

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

5 participants