'Fastlane scan failing randomly when testing SPM packages - IDEContainerErrorDomain Code=6

I have a project that consists of several SPM packages. I'm using Fastlane to perform tests on each of those packages, like so

lane :tests do
  TEST_PACKAGES.each { |package|
    single_test(package: package, devices: TEST_DEVICES)
  }
end

lane :single_test do |options|
  package = options[:package]
  devices = options[:devices]
  scan(
      package_path: package,
      scheme: package,
      devices: devices,
      output_directory: './' + package  + '/' + TEST_OUTPUT_DIR,
      buildlog_path: TEST_BUILDLOG_PATH,
      derived_data_path: DERIVED_DATA_PATH,
      code_coverage: true,
      result_bundle: true,
      fail_build: false,
      clean: true,
      configuration: "Debug"
    )     
end

The problem is that this will randomly fail - sometimes on first package, sometimes on second, and sometimes further, with errors similar to this one:

Error: Error Domain=com.apple.dt.IDEContainerErrorDomain Code=6 "Cannot open "swift-custom-dump" as a "Swift Package Proxy" because it is already open as a "Swift User Managed Package Folder"."

Several errors like that appear, referring to dependencies used by the specific package.

There is no consistency in this behaviour, as simply calling fastlane tests again, without any changes, will result in tests failing for different package.

What might be the cause?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source