Fix SharedType.PerTestSession not being respected with inheritance#3082
Fix SharedType.PerTestSession not being respected with inheritance#3082
Conversation
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
…ourceGenerator Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
SharedType.PerTestSession not being respected with inheritance|
Claude finished @Copilot's task —— View job PR Review: Fix SharedType.PerTestSession inheritance
|

The
SharedType.PerTestSessionsharing behavior was not working correctly whenClassDataSourceattributes were defined on intermediate base classes in an inheritance hierarchy.Problem
When using inheritance with
ClassDataSourceproperties, the sharing mechanism would fail if the attributes were moved from the concrete class to an abstract base class:In the broken scenario, containers would be disposed after the first test class finished instead of being shared across the entire test session.
Root Cause
The
PropertyInjectionSourceGeneratorwas incorrectly setting theContainingTypemetadata to the concrete class (classSymbol) rather than the actual class where the property was declared (propInfo.Property.ContainingType). This caused the test class type resolution to vary between concrete classes, breaking the global sharing behavior expected forPerTestSession.Fix
Updated the source generator to use the correct containing type:
This ensures consistent sharing behavior across inheritance hierarchies by using the type where the property was actually declared, not where it's being consumed.
Fixes #3064.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.