XCTestCase Async Setup Function Always Causes Leak in Instruments

I'm developing a library and using XCTest for unit tests. While trying to profile the test suite, I noticed that Instruments seems to report a leak every single time the async throwing setup function is called, no matter what.

For example,

This will report a leak:

final class LeakTests: XCTestCase {
    
    override func setUp() async throws {
        try await super.setUp()
    }
 
    func testLeak() async throws {
        try await Task.sleep(nanoseconds: 5_000_000_000)
    }
}

This will not report a leak:

final class LeakTests: XCTestCase {
    
//    override func setUp() async throws {
//        try await super.setUp()
//    }
 
    func testLeak() async throws {
        try await Task.sleep(nanoseconds: 5_000_000_000)
    }
}

Any ideas on why this might be happening, or should I just file a bug report? It makes it quite difficult to use the leak detection for unit tests, as it shows hundreds of leaks when the whole suite is ran.

You're probably encountering a bug in XCTest, Swift, or Instruments - just commenting out this implementation of setUp() definitely shouldn't cause leaks. Please file a feedback report with detailed steps to reproduce the issue (including the Xcode and OS versions of the device(s) you're building and running with). It'd be great if you could attach a small project which reproduces the issue when running a test case.

Thanks, I just submitted a report for it here.

XCTestCase Async Setup Function Always Causes Leak in Instruments
 
 
Q