pestphp / pestphp/pest

[4.x] beforeEach runs even when skipped

Open
#1,329 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
11.7k
Forks
538
Avg merge
4d 11h
Merged PRs (30d)
8

Description

What Happened

beforeEach runs before checking skip() both when on test or directly on beforeEach.

I would expect that skip check takes precedence.

How to Reproduce
beforeEach(fn () => dump('beforeEach'))
    ->skip(fn () => dump('skip'));

test('should not run', fn () => dump('this test should not run'));

output:

"beforeEach" // tests\Feature\Api\pestTest.php:3
"skip" // tests\Feature\Api\pestTest.php:4

This test was ignored.

Sample Repository

No response

Pest Version

3.7.1

PHP Version

8.3.14

Operation System

Windows

Notes

in case it's significant: Pest in Laravel app

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in tests\Feature\Api\pestTest.php using Pest 3.7.1, PHP 8.3.14, and the reported Laravel setup. Trace the handling of beforeEach and skip() to determine their execution order. Done means a skipped test does not run its beforeEach callback, while the skip is still reported.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.