Skip to content

Commit c3eff76

Browse files
scitechSkn0tt
andauthored
fix: show not_ prefix in call log when negative assertions fail (#3033)
Co-authored-by: Simon Knott <info@simonknott.de>
1 parent 62edef4 commit c3eff76

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

playwright/_impl/_assertions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ async def _expect_impl(
9898
expect_options["timeout"] = self._timeout or 5_000
9999
if expect_options["isNot"]:
100100
message = message.replace("expected to", "expected not to")
101+
if title:
102+
title = title.replace('"to_', '"not_to_')
101103
if "useInnerText" in expect_options and expect_options["useInnerText"] is None:
102104
del expect_options["useInnerText"]
103105
result = await self._call_expect(expression, expect_options, title)

tests/async/test_assertions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,15 @@ async def test_should_be_able_to_set_custom_timeout(page: Page) -> None:
10241024
assert 'Expect "to_be_visible" with timeout 111ms' in str(exc_info.value)
10251025

10261026

1027+
async def test_negative_assertion_shows_not_prefix_in_call_log(
1028+
page: Page,
1029+
) -> None:
1030+
await page.set_content("<button>hello</button>")
1031+
with pytest.raises(AssertionError) as exc_info:
1032+
await expect(page.locator("button")).not_to_be_visible(timeout=111)
1033+
assert 'Expect "not_to_be_visible" with timeout 111ms' in str(exc_info.value)
1034+
1035+
10271036
async def test_should_be_able_to_set_custom_global_timeout(page: Page) -> None:
10281037
try:
10291038
expect.set_options(timeout=111)

0 commit comments

Comments
 (0)