Skip to content

Keep a nested run out of the parallel worker's output tape - #3085

Merged
nohwnd merged 1 commit into
mainfrom
fix-2991-nested-tape
Nov 12, 2026
Merged

nohwnd merged 1 commit into
mainfrom
fix-2991-nested-tape

Conversation

@nohwnd

@nohwnd nohwnd commented Nov 11, 2026

Copy link
Copy Markdown
Member

Fix #2991

A worker silences its run and appends everything it writes to a module-scope tape, so the parent can replay it in order. The tape is module scope, so a run that starts inside the worker's run saw it as well. A test that calls Invoke-Pester itself and captures the output with 6>&1 got nothing back, while that output went to the tape and the parent replayed it later as if the worker had written it.

A nested run belongs to its own caller, so it now puts the tape aside for its duration and gives it back when it ends. Invoke-Pester already knows whether it is nested, $runningPesterInPester, and already has the finally that restores the outer run's global mocks, so the tape rides along with that. A worker's own run is not nested, so it keeps the tape.

The repro is in our own suite. tst/functions/Output.Tests.ps1 with Run.Parallel on:

before: passed=78 failed=4
after:  passed=82 failed=0

The four failures were the tags rendering tests, which capture the output of a run they start themselves.

The test in tst/Pester.RSpec.Parallel.ts.ps1 fails without the fix, on the second assertion: the parent's own captured output contains the nested run's Describing InnerNested line, which is the replay.

./test.ps1 -NoBuild on this branch: 3037 passed, 0 failed, 3 skipped.

🤖

A worker silences its run and appends everything it writes to a module-scope
tape, so the parent can replay it in order. The tape is module scope, so a run
that starts inside the worker's run saw it as well: a test that calls
Invoke-Pester itself and captures the output with 6>&1 got nothing back, while
that output went to the tape and the parent replayed it later as if the worker
had written it.

A nested run belongs to its own caller, so it now puts the tape aside for its
duration and gives it back when it ends. Invoke-Pester already knows whether it
is nested, and already has the finally that restores the outer run's global
mocks, so the tape rides along with that. A worker's own run is not nested, so
it keeps the tape.

🤖
@nohwnd
nohwnd merged commit 8c6fb87 into main Nov 12, 2026
14 checks passed
@nohwnd
nohwnd deleted the fix-2991-nested-tape branch November 12, 2026 18: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.

Nested Invoke-Pester inside a parallel worker sends its output to the tape instead of the caller

1 participant