Fix $PSDefaultParameterValues leak causing tests to skip unexpectedly (#26602)

This fixes test isolation issues where six test files were leaking $PSDefaultParameterValues["It:Skip"] settings to subsequent tests, causing widespread test skipping on Linux. The fixes address two distinct patterns: using .Remove() which doesn't restore the original state (4 files), and imbalanced Push-DefaultParameterValueStack/Pop-DefaultParameterValueStack calls (2 files).
This commit is contained in:
Copilot
2025-12-12 09:26:46 +05:00
committed by GitHub
parent 06ffbaeb44
commit 2e7765eef1
6 changed files with 10 additions and 6 deletions
@@ -3,6 +3,8 @@
Describe "CIM Objects are adapted properly" -Tag @("CI") {
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
function getIndex
{
param([string[]]$strings,[string]$pattern)
@@ -32,7 +34,7 @@ Describe "CIM Objects are adapted properly" -Tag @("CI") {
}
}
AfterAll {
$PSDefaultParameterValues.Remove("it:pending")
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}
It "Namespace-qualified Win32_Process is present" -Skip:(!$IsWindows) {
@@ -83,9 +83,7 @@ Describe "JEA session Transcript script test" -Tag @("Feature", 'RequireAdminOnW
AfterAll {
if ($skipTest) {
Pop-DefaultParameterValueStack
return
}
Pop-DefaultParameterValueStack
}
It "Configuration name should be in the transcript header" {
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
try {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if ( ! $IsWindows ) {
$PSDefaultParameterValues['it:skip'] = $true
}
@@ -52,5 +53,5 @@ try {
}
}
finally {
$PSDefaultParameterValues.remove("it:skip")
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}
@@ -89,6 +89,7 @@ Describe "Windows file content signatures" -Tags @('Feature', 'RequireAdminOnWin
AfterAll {
if ($shouldSkip) {
Pop-DefaultParameterValueStack
return
}