How to turn off parallel execution of tests for multi-project builds?

Viewed 20591

I have a multi-project build with tests in sub-projects and in a parent project. The build is aggregated so that the parent project runs all tests in child projects.

I configured it so that there's no parallel execution of tests in both the sub-projects and the parent project, via

parallelExecution in Test := false

However, I have the nagging feeling that tests that span over multiple projects are ran in parallel. In the case of one of the sub-projects this is a problem because it mutates state in a test database concurrently, leading to the test to fail.

Any ideas as to how to globally switch of parallel execution of tests, between projects?

7 Answers

This worked for me in 1.1.0:

Test / parallelExecution := false

You can try also Global / parallelExecution := false

The "modern" (i.e. sbt 1.x) equivalent of disabling parallel execution in Test scope is to add the following to your build.sbt:

Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)

For those not familiar with sbt syntax, in context you want to do something like:

lazy val main = project
  .in(file("."))
  .settings(
    name := "foo",
    // more settings
    // ...
    Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)
  )

From the tags and rules section of sbt docs.

p.s. quite a useful setting for ScalaTest, particularly around setup/teardown logic during database testing. Fixes some quite puzzling non-deterministic errors that you'll ineviitably hit with parallel execution enabled.

Related