Conversation
Fix #3044 `Invoke-InRunspacePool` creates the pool with the caller's `$Host`, so a worker's `Write-Warning` already reaches the console while the worker runs. The loop that re-emitted `Streams.Warning` after `EndInvoke` printed every warning a second time, and a third time for the workers that started first. Errors are different, they only land in `Streams.Error` and never reach the host on their own, so that re-emit stays. Added tests for both, the warning one fails without the fix. 🤖
Contributor
|
@nohwnd So the workers will surface warnings anyway but only when running tests in parallel? I went through the changelog for 6.2.0 and didn't see that. Tests running serially or in parallel on 6.0.0, 6.1.0 do not surface warnings. Was this a bug, that the warnings were not surfacing or the current change is a breaking change? Tests running serially and then parallelly on Pester 6.2.0: vs tests running serially and parallelly on Pester 6.1.0: |
A worker runspace starts with every preference variable at its default, so it decided on its own what to print. A caller who had silenced warnings still got them, and a caller who had asked for verbose output got none. Both differ from what the same files print in a sequential run, where the test body resolves these variables from the caller's scope. Invoke-Pester hands its caller's session state to Invoke-TestInParallel, which reads WarningPreference, VerbosePreference, DebugPreference, InformationPreference and ProgressPreference from it and defines them in every worker runspace. ErrorActionPreference is left out on purpose, it decides how a command behaves on error and not only what reaches the screen. Write-Host is unaffected either way, it is not preference-controlled and already printed once in both modes. 🤖
nohwnd
added a commit
that referenced
this pull request
Sep 29, 2026
#3045 grew a second commit, the workers now take the caller's preference variables as well. The notes said only that the duplicate warnings were gone.
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.


Fix #3044
Two things made
Run.Parallelprint something different from a sequential run of the same files.Every warning was printed twice, and three times for the workers that started first.
Invoke-InRunspacePoolcreates the runspace pool with the caller's$Host, so a worker'sWrite-Warningalready reaches the console while the worker runs. The loop that re-emittedStreams.WarningafterEndInvokeprinted it again. Errors keep their re-emit, they only land inStreams.Errorand never reach the host on their own. Regression from pester/Pester#2987 - Run test files in parallel on Windows PowerShell 5.1 too.A worker ran with default preference variables. A fresh runspace has
WarningPreference = 'Continue'andVerbosePreference = 'SilentlyContinue'no matter what the caller was running with, so a caller who had silenced warnings still got them and a caller who had asked for verbose output got none.Invoke-Pesternow hands its caller's session state down, and the worker runspaces are defined withWarningPreference,VerbosePreference,DebugPreference,InformationPreferenceandProgressPreferencetaken from it. This one is not new in 6.2.0, 6.1.0 lost the verbose output the same way, warnings only looked right there becauseForEach-Object -Parallelmerged the worker's records into the parent's stream where the caller's preference filtered them.One test writing to every stream, counting how many times each line reaches the console:
Write-HostWrite-ErrorWrite-Warningand with the caller setting
WarningPreference = 'SilentlyContinue',VerbosePreference = 'Continue':Write-WarningWrite-VerboseWrite-Hostis unaffected throughout, it is not preference-controlled and already printed once in both modes.Added tests for both. The warning one fails with the re-emit loop put back, the preference one fails with the wiring removed. The preference test runs in a child process, because a worker writes to the shared host and no redirection inside the test process can see that.
ErrorActionPreferenceis left out on purpose, it decides how a command behaves on error and not only what reaches the screen. A sequential test body does inherit it, so this is a known remaining difference. Worth folding in, or leaving?🤖