Contents

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 throws

Parameters

  • test:

    The test which function encapsulates.

  • testCase:

    The test case, if any, which function encapsulates. When invoked on a suite, the value of this argument is nil.

  • function:

    The function to perform. If test represents a test suite, this function encapsulates running all the tests in that suite. If test represents 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.