I just stumbled across this while teaching myself how to use TestScoping. If a Suite Trait test scoping fails to also conform to TestSuite, I observe a runtime crash.
Am I doing something wrong or could the runtime be smarter about detecting the missing conformance and fail more gracefully?
This is by design (it's an assertion failure), however we are planning to revisit the design of suite traits and adjust this behaviour.
@briancroom, @smontgomery, and I need to squabble over discuss it a bit more, but IMHO it is likely that we would treat the trait you have as recursively applying to suites nested in the outermost suite, but not to tests, and that you'd need to add TestTrait conformance to make it also apply to tests in that suite.
I don't think we currently have a GitHub issue tracking this change, so please feel free to file one!
It makes sense that one would need the TestTrait conformance to be able to wrap test functions. I'm just wondering if there's better way to handle this condition. I was able to figure out, but others might not be so lucky.
To be clear, I wasn't seeing any kind of assertion message either. It was @grynspan who identified the assertion from my stack trace.
Note that the "TestCase" argument to the callback has a boolean isSuite to differentiate between suites and test functions.
Can you elaborate on what you mean by differentiating between provideScope methods for SuiteTrait and TestTrait? In my implementation, I have a single struct that conforms to both protocols, so there's just one unique provideScope method. How are you doing it?
public struct SuiteSetup: SuiteTrait, TestTrait, TestScoping {
public let isRecursive: Bool = true
public init() {}
public func provideScope(for test: Test, testCase: Test.Case?, performing testFunction: @Sendable () async throws -> Void) async throws {
// do some global setup stuff
try await testFunction()
// do some global cleanup stuff
}
}