admin管理员组

文章数量:1289910

I've had this issue in a project of mine and I've setup a minimal example reproducing the issue, it took me a while to figure out the problem.

But it seems that when I set Test / envVars in my build.sbt they aren't propagated to tests in a sub project

This is my build.sbt

    ThisBuild / scalaVersion := "3.3.1"

    Test / envVars := Map("TEST" -> "TEST_ENVVARS")
    Test / fork    := true

    lazy val subProject = project
      .in(file("sub-project"))
      .settings(
        libraryDependencies ++= Seq(
          ".scalatest" %% "scalatest" % "3.2.9" % Test
        )
      )
    lazy val root = project
      .in(file("."))
      .aggregate(subProject)
      .settings(
        libraryDependencies ++= Seq(
          ".scalatest" %% "scalatest" % "3.2.9" % Test
        )
      )

I have two identical tests, one in the "root" of the project and one in "sub-project" directory src/test/scala/example/RootExampleTest.scala and sub-project/src/test/scala/example/SubProjectExampleTest.scala

They both look like this with the exception of the class name

package example

    import .scalatest.flatspec.AnyFlatSpec
    import scala.util.Properties
    
    class RootExampleTest extends AnyFlatSpec {
      "RootExampleTest" should "read envVars" in {
        assert(Properties.envOrNone("TEST").nonEmpty)
      } 
    }

when I run the test with sbt test the SubProjectExampleTest fails but the RootExampleTest succeeds.

I was expecting that the sub-project would also have the envVars propagated

本文标签: scalasbt envVars not propagated to subprojectsStack Overflow