Skip to content

fix: parallel runs with group filters no longer exit 1 despite green tests - #1757

Closed
User7142 wants to merge 1 commit into
pestphp:4.xfrom
User7142:fix/parallel-group-filtered-empty-suite
Closed

User7142 wants to merge 1 commit into
pestphp:4.xfrom
User7142:fix/parallel-group-filtered-empty-suite

Conversation

@User7142

@User7142 User7142 commented Jul 16, 2026 •

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature

Description:

--parallel runs that use --group/--exclude-group can exit 1 with a fully green summary and no error output.

Cause: a wrapper worker's serialized TestResult only carries the numberOfTests of the last file it executed (PHPUnit's Collector overwrites the counter on every executionStarted). If a worker's final file has all tests excluded by the group filter, it reports hasTests() === false despite having run tests. When every worker ends on such a file — a timing lottery, hence flaky — the merged result in WrapperRunner::complete() claims the suite was empty, and since PHPUnit 12 enables failOnEmptyTestSuite implicitly for explicit selections, the run exits 1. The "No tests found" runner warnings are already filtered from the output, so nothing is printed.

Deterministic repro (fails before this fix, passes after — added as a test):

php bin/pest --parallel --processes=1 --group=filtered-group tests/.tests/ParallelGroupFilteredLastFile
# "Tests: 1 passed (1 assertions)" — exit code 1

Fix: while merging worker results, treat a worker with numberOfTestsRun() > 0 as having tests. A companion test ensures genuinely empty selections still exit non-zero.

Related:

…tests

In parallel mode each wrapper worker's serialized TestResult only carries
the `numberOfTests` of the *last* file it executed — PHPUnit's Collector
overwrites the counter on every `executionStarted` event. When a worker's
final file has all of its tests excluded by `--group`/`--exclude-group`,
that worker reports `hasTests() === false` even though it ran plenty of
tests.

If every worker happens to end on such a fully-filtered file, the merged
TestResult claims the whole suite was empty. Because PHPUnit 12 enables
`failOnEmptyTestSuite` implicitly whenever an explicit test selection is
present (TextUI\Configuration\Merger), the run then exits 1 — with a fully
green summary and no error output whatsoever. Which worker ends on which
file is a timing lottery, so this manifests as a flaky, silent CI failure
(likely the root cause of pestphp#1483).

Fix: while merging worker results, treat a worker that actually ran tests
(`numberOfTestsRun() > 0`) as having tests. Genuinely empty selections
(no worker ran anything) still exit non-zero.

Deterministic reproduction (before this fix):

    php bin/pest --parallel --processes=1 --group=filtered-group \
        tests/.tests/ParallelGroupFilteredLastFile
    # Tests: 1 passed (1 assertions) — exit code 1

With `--processes=1` the single worker deterministically ends on
ZTest.php, whose only test is outside the filtered group.
@CovertError

Copy link
Copy Markdown

it would be amazing if this is gets merged if it fixes this annoying issue @nunomaduro

@User7142
User7142 force-pushed the fix/parallel-group-filtered-empty-suite branch from dd94477 to 8c2e158 Compare October 2, 2026 16:20
@nunomaduro

Copy link
Copy Markdown
Member

thank you! can you target 5.x + add a test? 4.x only gets security fixes now.

@User7142

Copy link
Copy Markdown
Author

Thanks! The fix itself is already on 5.x via 942d6ae (numberOfTestsSeenByWorker()), so I've opened #1985 against 5.x with just the regression tests. It fails when that fix is reverted. Closing this one in favour of #1985.

@User7142 User7142 closed this Oct 20, 2026
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.

3 participants