diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs index a24f169e6c..c3bd509f26 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs @@ -524,13 +524,14 @@ private SynchronizedStringBuilder GetTestContextMessagesStringBuilder() /// A fresh context suitable for one folded data-driven iteration. internal TestContextImplementation CloneForDataDrivenIteration() { - // Pass testMethod: null and testClassFullName: null because the relevant labels - // (including TestNameLabel / FullyQualifiedTestClassNameLabel and anything merged from - // AssemblyInitialize / ClassInitialize) are already in _properties. In that branch the - // constructor takes a shallow copy of the passed dictionary, so passing _properties - // directly gives the clone an isolated property bag without an extra intermediate copy: - // per-iteration mutations to the clone's property bag won't leak back to this instance - // nor to subsequent iterations. + // Pass _properties directly and testMethod: null / testClassFullName: null because the + // relevant labels (including TestNameLabel / FullyQualifiedTestClassNameLabel and anything + // merged from AssemblyInitialize / ClassInitialize) are already in the property bag. The + // constructor's null/null branch copies the supplied properties into a fresh dictionary + // via the [with(properties)] spread, so no intermediate snapshot allocation is needed and + // isolation is preserved: per-iteration mutations to the clone's property bag won't leak + // back to this instance nor to subsequent iterations, and mutations to this instance after + // clone creation won't leak into the clone. var clone = new TestContextImplementation(testMethod: null, testClassFullName: null, _properties, _messageLogger, _testRunCancellationToken); // Preserve TestRunCount so user code that observes it (e.g. retry-aware tests) sees