Skip to content

Make a parallel run print what a sequential run prints - #3045

Open
nohwnd wants to merge 2 commits into
mainfrom
nohwnd-parallel-duplicate-warnings
Open

nohwnd wants to merge 2 commits into
mainfrom
nohwnd-parallel-duplicate-warnings

Conversation

@nohwnd

@nohwnd nohwnd commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Fix #3044

Two things made Run.Parallel print 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-InRunspacePool creates the runspace 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 it again. Errors keep their re-emit, they only land in Streams.Error and 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' and VerbosePreference = '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-Pester now hands its caller's session state down, and the worker runspaces are defined with WarningPreference, VerbosePreference, DebugPreference, InformationPreference and ProgressPreference taken 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 because ForEach-Object -Parallel merged 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:

Stream serial parallel 6.2.0 parallel, this PR
Write-Host 1 1 1
Write-Error 1 1 1
Write-Warning 1 2 1

and with the caller setting WarningPreference = 'SilentlyContinue', VerbosePreference = 'Continue':

Stream serial parallel 6.2.0 parallel, this PR
Write-Warning 0 1 0
Write-Verbose 1 0 1

Write-Host is 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.

  • ErrorActionPreference is 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?

🤖

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.

🤖
@kborowinski

kborowinski commented Sep 24, 2026 •

Copy link
Copy Markdown
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:
image
Warning output surfacing only when running in parallel

vs tests running serially and parallelly on Pester 6.1.0:
image
Warning output not surfacing at all

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 nohwnd changed the title Print a parallel worker's warnings once, not two or three times Make a parallel run print what a sequential run prints Sep 29, 2026
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.
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.

Warning stream is visible when running tests in parallel on Pester 6.2.0

2 participants