File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,13 +36,20 @@ internal static class TestContextExtensions
3636 /// <summary>
3737 /// Checks if the class instance has changed since caches were built, and invalidates if needed.
3838 /// </summary>
39+ /// <remarks>
40+ /// Class instances change in these scenarios:
41+ /// - Test retries: A new instance is created for each retry attempt
42+ /// - Keyed test instances: Different data combinations may use different instances
43+ /// When this happens, eligible event objects may include the new instance (if it implements
44+ /// event receiver interfaces), so all caches must be invalidated and rebuilt.
45+ /// </remarks>
3946 private static void InvalidateCachesIfClassInstanceChanged ( TestContext testContext )
4047 {
4148 var currentClassInstance = testContext . Metadata . TestDetails . ClassInstance ;
4249 if ( testContext . CachedClassInstance != null &&
4350 ! ReferenceEquals ( testContext . CachedClassInstance , currentClassInstance ) )
4451 {
45- // Class instance changed (e.g., on retry), invalidate all caches
52+ // Class instance changed - invalidate all caches so they're rebuilt with the new instance
4653 testContext . InvalidateEventReceiverCaches ( ) ;
4754 }
4855 testContext . CachedClassInstance = currentClassInstance ;
You can’t perform that action at this time.
0 commit comments