Skip to content

Fix #2585: Prevent $WhatIfPreference from breaking Pester#2730

Merged
nohwnd merged 1 commit into
mainfrom
fix/2585-whatifpreference
Jun 17, 2026
Merged

Fix #2585: Prevent $WhatIfPreference from breaking Pester#2730
nohwnd merged 1 commit into
mainfrom
fix/2585-whatifpreference

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes #2585

When \$WhatIfPreference = \$true leaks into Pester from the caller's scope, internal commands like New-Item and Remove-Item get 'What if:' output instead of executing, causing test discovery and execution to fail.

Sets \$WhatIfPreference = \$false at the start of Invoke-Pester to isolate Pester internals from the caller's preference. The caller's own \$WhatIfPreference is not modified.

Set $WhatIfPreference = $false at the start of Invoke-Pester's begin
block. When a caller sets $WhatIfPreference = $true, it leaks into
Pester's internal commands (New-Item, Remove-Item, etc.) and causes
test execution to fail with cryptic errors or excessive 'What if:'
messages. The local assignment scopes it to Invoke-Pester and its
children without affecting the caller's preference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd merged commit 77798ba into main Jun 17, 2026
13 checks passed
@nohwnd nohwnd deleted the fix/2585-whatifpreference branch June 17, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pester Test Execution Fails When $WhatIfPreference is Enabled

1 participant