File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed
Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -55,9 +55,9 @@ async def _expect_impl(
5555 if log :
5656 log = "\n Call log:\n " + log
5757 if self ._custom_message :
58- out_message = (
59- f" { self . _custom_message } \n Expected value: { expected or '< None>' } "
60- )
58+ out_message = self . _custom_message
59+ if expected is not None :
60+ out_message += f" \n Expected value: ' { expected or '<None>' } '"
6161 else :
6262 out_message = (
6363 f"{ message } '{ expected } '" if expected is not None else f"{ message } "
Original file line number Diff line number Diff line change @@ -671,3 +671,20 @@ async def test_should_print_users_message_for_page_based_assertion(
671671 with pytest .raises (AssertionError ) as excinfo :
672672 await expect (page ).to_have_title ("old title" , timeout = 100 )
673673 assert "Page title expected to be" in str (excinfo .value )
674+
675+
676+ async def test_should_print_expected_value_with_custom_message (
677+ page : Page , server : Server
678+ ) -> None :
679+ await page .goto (server .EMPTY_PAGE )
680+ await page .set_content ("<title>new title</title>" )
681+ with pytest .raises (AssertionError ) as excinfo :
682+ await expect (page , "custom-message" ).to_have_title ("old title" , timeout = 100 )
683+ assert "custom-message" in str (excinfo .value )
684+ assert "Expected value: 'old title'" in str (excinfo .value )
685+ with pytest .raises (AssertionError ) as excinfo :
686+ await expect (page .get_by_text ("hello" ), "custom-message" ).to_be_visible (
687+ timeout = 100
688+ )
689+ assert "custom-message" in str (excinfo .value )
690+ assert "Expected value" not in str (excinfo .value )
Original file line number Diff line number Diff line change @@ -759,3 +759,18 @@ def test_should_print_users_message_for_page_based_assertion(
759759 with pytest .raises (AssertionError ) as excinfo :
760760 expect (page ).to_have_title ("old title" , timeout = 100 )
761761 assert "Page title expected to be" in str (excinfo .value )
762+
763+
764+ def test_should_print_expected_value_with_custom_message (
765+ page : Page , server : Server
766+ ) -> None :
767+ page .goto (server .EMPTY_PAGE )
768+ page .set_content ("<title>new title</title>" )
769+ with pytest .raises (AssertionError ) as excinfo :
770+ expect (page , "custom-message" ).to_have_title ("old title" , timeout = 100 )
771+ assert "custom-message" in str (excinfo .value )
772+ assert "Expected value: 'old title'" in str (excinfo .value )
773+ with pytest .raises (AssertionError ) as excinfo :
774+ expect (page .get_by_text ("hello" ), "custom-message" ).to_be_visible (timeout = 100 )
775+ assert "custom-message" in str (excinfo .value )
776+ assert "Expected value" not in str (excinfo .value )
You can’t perform that action at this time.
0 commit comments