fix: evaluate SkipAttribute before data source initialization#4743
Merged
fix: evaluate SkipAttribute before data source initialization#4743
Conversation
Derived SkipAttribute subclasses (e.g., skip-in-CI attributes) set SkipReason during OnTestRegistered, but the execution path called CreateInstanceAsync() — triggering expensive IAsyncInitializer calls — before checking SkipReason. If initialization threw (e.g., no database in CI), the test was marked as failed instead of skipped. Three layered fixes: 1. TestFilterService.RegisterTest: fire OnTestRegistered event receivers BEFORE RegisterTestArgumentsAsync, and skip argument registration entirely when SkipReason is set. This prevents ClassDataSource initialization for skipped tests during the registration phase. 2. TestCoordinator.ExecuteTestInternalAsync: check SkipReason before entering retry/timeout logic and instance creation. 3. TestCoordinator.ExecuteTestLifecycleAsync: check SkipReason before CreateInstanceAsync() to prevent data source initialization that would fail or waste resources for skipped tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 12, 2026
This was referenced Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4737
OnTestRegisteredevent receivers (includingSkipAttribute) beforeRegisterTestArgumentsAsyncinTestFilterService.RegisterTest, and skip argument registration entirely whenSkipReasonis set. This preventsClassDataSourceinitialization for tests that should be skipped.SkipReasoninExecuteTestInternalAsyncbefore entering retry/timeout logic and instance creation, avoiding unnecessary work for already-skipped tests.SkipReasoninExecuteTestLifecycleAsyncbeforeCreateInstanceAsync()to prevent data sourceIAsyncInitializercalls that would fail or waste resources for skipped tests.Root cause
Derived
SkipAttributesubclasses (e.g., CI-environment skip attributes) evaluateShouldSkip()at runtime duringOnTestRegistered. Previously,RegisterTestArgumentsAsyncran before event receivers, andCreateInstanceAsync()(which triggersIAsyncInitializer.InitializeAsync()on data sources) ran before theSkipReasoncheck. If initialization threw (e.g., database unavailable in CI), the exception escaped before the skip check could run, marking the test as failed instead of skipped.Test plan
SkipAttribute+ClassDataSourcewith failingIAsyncInitializer→ test is skipped, not failedSkipAttribute+ClassDataSourcewith succeeding initializer → test is skippedSkipTests,DynamicSkipReasonTests,SkipInHooksTests,SkipTestExceptionTestsDataSourceCountTests,DataSourceExceptionPropagationTests,GenericMethodWithDataSourceTests,PropertyInjectionInitFailureTests🤖 Generated with Claude Code