Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -524,16 +524,15 @@ private SynchronizedStringBuilder GetTestContextMessagesStringBuilder()
/// <returns>A fresh context suitable for one folded data-driven iteration.</returns>
internal TestContextImplementation CloneForDataDrivenIteration()
{
// Take a shallow snapshot of the current property bag so that the clone starts with
// the same properties (including TestNameLabel / FullyQualifiedTestClassNameLabel and
// anything merged from AssemblyInitialize / ClassInitialize) but is otherwise isolated.
// Per-iteration mutations to the clone's property bag won't leak back to this instance
// nor to subsequent iterations.
var snapshot = new Dictionary<string, object?>(_properties);

// Pass testMethod: null and testClassFullName: null because the relevant labels are
// already in the snapshot. The constructor will copy the snapshot as-is.
var clone = new TestContextImplementation(testMethod: null, testClassFullName: null, snapshot, _messageLogger, _testRunCancellationToken);
// 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
// the same value it would see in the unfolded path. TestRunCount represents the
Expand Down