Skip to content

feat(assertions): add expect.soft() for collecting multiple failures#3065

Open
Skn0tt wants to merge 1 commit intomicrosoft:mainfrom
Skn0tt:feat/soft-assertions
Open

feat(assertions): add expect.soft() for collecting multiple failures#3065
Skn0tt wants to merge 1 commit intomicrosoft:mainfrom
Skn0tt:feat/soft-assertions

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented May 4, 2026

Summary

  • Adds JS-style expect.soft(locator).to_have_text(...) that records failures into a per-scope collector instead of raising.
  • The collector scope is established by the pytest plugins (feat: aggregate expect.soft() failures per test playwright-pytest#312) via an autouse fixture that re-raises collected failures (or a BaseExceptionGroup) at end of test.
  • Outside an active scope, expect.soft(...).<assertion>(...) raises RuntimeError so the missing plugin requirement is obvious instead of silently behaving as a hard assertion.

Fixes #1272

Companion PR (pytest plugin integration): microsoft/playwright-pytest#312

Adds JS-style soft assertions: `expect.soft(locator).to_have_text(...)`
records the failure into a per-scope collector instead of raising. A
collector scope is established by `pytest-playwright>=0.7.3` /
`pytest-playwright-asyncio>=0.7.3` via an autouse fixture that re-raises
collected failures (or a `BaseExceptionGroup`) at end of test.

Outside of an active scope, soft assertions raise `RuntimeError` to make
the missing plugin requirement obvious instead of silently behaving as
hard assertions.

References microsoft#1272
"""
Creates a [soft assertion](https://playwright.dev/python/docs/test-assertions#soft-assertions).
Failing soft assertions do not abort test execution, but mark the test
as failed. Multiple failures from the same test are surfaced together
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mention this requires the pytest-playwright plugin.

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.

[Feature] Add soft assertions

2 participants