Read the mock parameter filter marker directly instead of Get-Variable#2916
Open
nohwnd wants to merge 1 commit into
Open
Read the mock parameter filter marker directly instead of Get-Variable#2916nohwnd wants to merge 1 commit into
nohwnd wants to merge 1 commit into
Conversation
Test-ParameterFilter called Get-Variable -ErrorAction Ignore to save the previous value of ______isInMockParameterFilter before every filter evaluation, and Set-AssertionPassResult did the same on every passing Should-* assertion. The variable is now initialized once at module scope, so a direct $script: read works, is cheap, and is safe under strict mode, and the save/restore is a plain assignment without the conditional Remove-Variable. Also inlined Get-ConflictingParameterNames in Get-ContextToDefine (its body is the same variable read the function already does directly further down) and dropped an @() around an alias collection that already has .Count. 🤖
This was referenced Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test-ParameterFiltercalledGet-Variable -Scope Script -ErrorAction Ignoreto save the previous value of______isInMockParameterFilterbefore every parameter filter evaluation, andSet-AssertionPassResultdid the same lookup on every passingShould-*assertion.Get-Variablewith-ErrorAction Ignoreis expensive for something that runs this often, and the only reason for it was that the variable might not exist yet.The variable is now initialized once at module scope to
$false, so both places do a direct$script:read, which also stays safe underSet-StrictMode. The save/restore inTest-ParameterFilterbecomes a plain assignment, without the conditionalRemove-Variablebranch.Two small ride-alongs in the same file:
Get-ContextToDefineinlinesGet-ConflictingParameterNames(its whole body is the same$script:variable read the function already does directly a few lines below), and an@()wrapper is dropped around an alias collection that already has.Count.Verification: full suite green on macOS (inline and dot-sourced build),
Pester.Mock.RSpec.ts.ps1and the Mock.Tests.ps1 suite pass, including the tests that mixShouldinside-ParameterFilterwhere the marker controls throw-vs-collect behavior.Related perf PRs: #2914, #2915, #2917, #2918. Measured together they cut ~21% from four representative workloads (inline build, macOS).
🤖