Skip to content

Fix test property lifecycle scope - #10080

Merged
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/fix-test-property-scope
Jul 20, 2026
Merged

Fix test property lifecycle scope#10080
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/fix-test-property-scope

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

  • keep [TestProperty], test categories, and host-provided TCM properties scoped to the individual test lifecycle
  • seed assembly/class initialization and cleanup contexts only with source/run-level properties
  • preserve downward flow of properties written by AssemblyInitialize and ClassInitialize
  • cover constructor, test initialize, test body, test cleanup, dispose, class cleanup, assembly cleanup, and sibling-test isolation

Validation

  • MSTestAdapter.PlatformServices.UnitTests: 925 passed
  • TestContextPropertyFlowTests: 6 passed across net462, net8.0, and net10.0
  • Debug package build: 0 warnings, 0 errors

Fixes #10041

Keep per-test traits, categories, and TCM properties out of assembly and class lifecycle contexts while preserving downward flow from assembly and class initialization.

Fixes #10041

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 872b37f5-a59d-4cde-a730-df6c766ef8a7
Copilot AI review requested due to automatic review settings July 20, 2026 09:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Separates per-test metadata from assembly/class lifecycle properties, preventing property leakage between sibling tests while preserving initializer property flow.

Changes:

  • Adds distinct per-test and lifecycle property dictionaries.
  • Uses lifecycle-only properties for assembly/class initialization and cleanup.
  • Adds unit and acceptance regression coverage across the complete test lifecycle.
Show a summary per file
File Description
TestExecutionManagerTests.cs Tests TCM property isolation across lifecycle contexts and sibling tests.
TestContextPropertyFlowTests.cs Adds end-to-end property-scope coverage.
InternalAPI.Unshipped.txt Tracks the new internal runner overloads.
UnitTestRunner.TestFilter.cs Uses lifecycle properties during filtered-test cleanup.
UnitTestRunner.RunSingleTest.cs Separates test and lifecycle property inputs.
TestExecutionManager.Runner.cs Seeds and passes source-only lifecycle properties.

Review details

  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #10080

GradeTestNotes
A (90–100) mod TestContextPropertyFlowTests.
PropertiesSetInAssemblyInit
AndClassInitAreVisibleEverywhere
Updated expected summary count from 5 to 7; clean AAA with exit-code + summary assertions. No issues found.
A (90–100) new TestContextPropertyFlowTests.
PerTestPropertiesAreScopedToTheirTest
Focused integration test with two meaningful assertions; single behavior under test. No issues found.
A (90–100) new TestExecutionManagerTests.
RunTestsShouldKeepTcmPropertiesOut
OfClassLifecycleAndSiblingTestContexts
Clear AAA; AwesomeAssertions equality check verifies both sibling tests passed with correct scoping. No issues found.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · 49.9 AIC · ⌖ 5.74 AIC · ⊞ 8.9K · [◷]( · )

@Evangelink
Evangelink enabled auto-merge (squash) July 20, 2026 10:41
@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jul 20, 2026
@Evangelink
Evangelink merged commit 1285203 into main Jul 20, 2026
32 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/fix-test-property-scope branch July 20, 2026 10:55
@Evangelink

Copy link
Copy Markdown
Member Author

/backport to rel/4.3

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

@Evangelink backporting to rel/4.3 failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix test property lifecycle scope
Using index info to reconstruct a base tree...
M	src/Adapter/MSTestAdapter.PlatformServices/Execution/TestExecutionManager.Runner.cs
M	src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.RunSingleTest.cs
M	src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.TestFilter.cs
A	src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt
M	test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Adapter/MSTestAdapter.PlatformServices/Execution/TestExecutionManager.Runner.cs
CONFLICT (content): Merge conflict in src/Adapter/MSTestAdapter.PlatformServices/Execution/TestExecutionManager.Runner.cs
Auto-merging src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.RunSingleTest.cs
CONFLICT (content): Merge conflict in src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.RunSingleTest.cs
Auto-merging src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.TestFilter.cs
CONFLICT (content): Merge conflict in src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.TestFilter.cs
CONFLICT (modify/delete): src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt deleted in HEAD and modified in Fix test property lifecycle scope.  Version Fix test property lifecycle scope of src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt left in tree.
Auto-merging test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix test property lifecycle scope
Error: The process '/usr/bin/git' failed with exit code 128

NOTE: A PR will be created, but needs to be revised manually!

Evangelink added a commit that referenced this pull request Jul 21, 2026
…to rel/4.3) (#10110)

Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changes in TestContext.Properties Flow for ClassInitialize has unintended side effects

3 participants