Skip to content

SetTestContext should be done on the right ExecutionContext to correctly maintain async locals #5622

@Youssef1313

Description

@Youssef1313

Describe the bug

Verify.MSTest generates the following:

  [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Verify.MSTest.SourceGenerator", "1.0.0.0")]
  public global::Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext
  {
    get => global::VerifyMSTest.Verifier.CurrentTestContext.Value!.TestContext;
    set => global::VerifyMSTest.Verifier.CurrentTestContext.Value = new global::VerifyMSTest.TestExecutionContext(value, GetType());
  }

where CurrentTestContext is an async local that's expected to be read correctly when inside the test. This has regressed in 3.9.0.

We should propagate the execution context correctly when setting TestContext. After we have set TestContext, we should re-capture the execution context and use that in RunTestInitializeMethod

Metadata

Metadata

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions