provideScope(for:testCase:performing:)
Provide custom execution scope for a function call which is related to the specified test or test case.
Declaration
func provideScope(for test: Test, testCase: Test.Case?, performing function: @Sendable () async throws -> Void) async throwsParameters
- test:
The test which
functionencapsulates. - testCase:
The test case, if any, which
functionencapsulates. When invoked on a suite, the value of this argument isnil. - function:
The function to perform. If
testrepresents a test suite, this function encapsulates running all the tests in that suite. Iftestrepresents a test function, this function is the body of that test function (including all cases if the test function is parameterized.)
Discussion
When the testing library prepares to run a test, it starts by finding all traits applied to that test, including those inherited from containing suites. It begins with inherited suite traits, sorting them outermost-to-innermost, and if the test is a function, it then adds all traits applied directly to that functions in the order they were applied (left-to-right). It then asks each trait for its scope provider (if any) by calling scopeProvider(for:testCase:). Finally, it calls this method on all non-nil scope providers, giving each an opportunity to perform arbitrary work before or after invoking function.
This method should either invoke function once before returning, or throw an error if it’s unable to provide a custom scope.
Issues recorded by this method are associated with test.