Skip to content

Remove vestigial block setup/teardown#2908

Closed
nohwnd wants to merge 1 commit into
pester:mainfrom
nohwnd:remove-block-setup-teardown
Closed

Remove vestigial block setup/teardown#2908
nohwnd wants to merge 1 commit into
pester:mainfrom
nohwnd:remove-block-setup-teardown

Conversation

@nohwnd

@nohwnd nohwnd commented Jul 18, 2026

Copy link
Copy Markdown
Member

Draft, stacked on #2907 (which is stacked on #2906). Follow up to Frode's comment on #2907.

The block level setup/teardown is dead. New-EachBlockSetup, New-EachBlockTeardown and New-OneTimeBlockTeardown (and the never set New-OneTimeBlockSetup that #2907 already removed) are only ever called from the runtime tests. Real BeforeAll / BeforeEach / AfterAll / AfterEach go through the *Test* variants (New-OneTimeTestSetup, New-EachTestSetup, ...), so in a real run the Block.EachBlockSetup / OneTimeBlockSetup / EachBlockTeardown / OneTimeBlockTeardown properties are always null and the two reads in Invoke-Test are no-ops.

Removes:

  • the three functions
  • the four ScriptBlock properties on Pester.Block
  • the two always null reads in Invoke-Test
  • the runtime tests that exercised them. The two data availability tests keep their teardown check by switching to New-OneTimeTestTeardown.

The plugin block lifecycle (OneTimeBlockSetupStart, EachBlockTeardownEnd, ...) is a separate, live mechanism and is untouched.

These are genuinely dead so I deleted them rather than reaching for [ExcludeFromCodeCoverage()].

Minor breaking change, fine for 6.1.0.

Verification

Full test.ps1 run passes.

New-EachBlockSetup, New-EachBlockTeardown and New-OneTimeBlockTeardown are only
called from the runtime tests. Real Before/After go through the *Test* variants,
so the Block.EachBlockSetup / OneTimeBlockSetup / EachBlockTeardown /
OneTimeBlockTeardown properties are always null in a real run and the two reads
in Invoke-Test are no-ops.

Removes the three functions, the four Pester.Block properties, the two null
reads, and the runtime tests that exercised them (the data-availability tests
keep their teardown check via New-OneTimeTestTeardown). The plugin block
lifecycle (OneTimeBlockSetupStart, EachBlockTeardownEnd, ...) is untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fflaten

fflaten commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

About OneTimeBlock*, see #1219. Is BeforeAll -Context still planned? If so, we can't remove them after all.

@nohwnd
nohwnd force-pushed the remove-block-setup-teardown branch from b5648e9 to e8f4efc Compare July 18, 2026 20:39
@nohwnd nohwnd closed this Jul 19, 2026
@nohwnd

nohwnd commented Jul 19, 2026

Copy link
Copy Markdown
Member Author

Good point, let's keep them. The EachBlockSetup/EachBlockTeardown side is actually already executed in Invoke-Test (the outer setup/teardown around each child block), it just has no public way to set it, so it is scaffolding for #1219 rather than dead. OneTimeBlock* is not wired at runtime yet. Closing this, I'll look at wiring up #1219 (BeforeEach/AfterEach -Context) instead.

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.

2 participants