I had this same problem and found the solution over at the Swift Forums: https://forums.swift.org/t/xcode-and-swift-package-manager/44704
The TLDR is that the Swift PM cache directory needs to be outside of your main project directory and using -derivedDataPath messes that up. You need to use the -clonedSourcePackagesDirPath parameter as well to point to a directory outside of your project folder to fix it.
Post
Replies
Boosts
Views
Activity
@Accessibility inspector font We had the same issue, but discovered that when built with the iOS 17 SDK, only views that are part of the view hierarchy and have had a layout pass will have their trait collections properly updated. After updating the tests to 1. Set the overrideUserInterfaceStyle, 2. Add the view to the test hosts view hierarchy and, 3. Calling setNeedsLayout/layoutIfNeeded on the view would the traitCollection be properly updated. This view layout pass requirement is mentioned in a WWDC 23 video.