As described in the v5 readme, the fundamental change in Pester5 is that Pester now runs in two phases: Discovery and Run. During Discovery Pester finds all your tests, groups them together and filters them based on your filters. Then in the Run phase it will actually run them.
Splitting the work into two distinct phases, powers many of the features in this release, and enables many others to be implemented in the future.
For Discovery to work correctly, there are new rules to follow:
Put all your code into
AfterEach. Put no code directly into
Context or on the top of your file, without wrapping it in one of these blocks, unless you have a good reason to do so.
All misplaced code will run during Discovery, and its results won’t be available during Run.
This article offers more guidance and shows examples of what it means.