Provides a LazySuite, which is a suite whose test list is a generator function, and ContextSuite,which can run fixtures (setup/teardown functions or methods) for the context that contains its tests.
A suite with context.
A ContextSuite executes fixtures (setup and teardown functions or methods) for the context containing its tests.
The context may be explicitly passed. If it is not, a context (or nested set of contexts) will be constructed by examining the tests in the suite.
Factory for ContextSuites. Called with a collection of tests, the factory decides on a hierarchy of contexts by introspecting the collection or the tests themselves to find the objects containing the test objects. It always returns one suite, but that suite may consist of a hierarchy of nested suites.
The complex case where there are tests that don’t all share the same context. Groups tests into suites with common ancestors, according to the following (essentially tail-recursive) procedure:
Starting with the context of the first test, if it is not None, look for tests in the remaining tests that share that ancestor. If any are found, group into a suite with that ancestor as the context, and replace the current suite with that suite. Continue this process for each ancestor of the first test, until all ancestors have been processed. At this point if any tests remain, recurse with those tests as the input, returning a list of the common suite (which may be the suite or test we started with, if no common tests were found) plus the results of recursion.