File tree Expand file tree Collapse file tree 3 files changed +10
-2
lines changed Expand file tree Collapse file tree 3 files changed +10
-2
lines changed Original file line number Diff line number Diff line change
1
+ Improve quoting in ``raises `` match failure message.
Original file line number Diff line number Diff line change @@ -544,7 +544,7 @@ def match(self, regexp):
544
544
"""
545
545
__tracebackhide__ = True
546
546
if not re .search (regexp , str (self .value )):
547
- assert 0 , "Pattern '{!s}' not found in '{!s}' " .format (regexp , self .value )
547
+ assert 0 , "Pattern {!r} not found in {!r} " .format (regexp , str ( self .value ) )
548
548
return True
549
549
550
550
Original file line number Diff line number Diff line change @@ -220,13 +220,20 @@ def test_raises_match(self):
220
220
int ("asdf" )
221
221
222
222
msg = "with base 16"
223
- expr = r"Pattern '{}' not found in ' invalid literal for int\(\) with base 10: 'asdf'' " .format (
223
+ expr = r"Pattern '{}' not found in \" invalid literal for int\(\) with base 10: 'asdf'\" " .format (
224
224
msg
225
225
)
226
226
with pytest .raises (AssertionError , match = expr ):
227
227
with pytest .raises (ValueError , match = msg ):
228
228
int ("asdf" , base = 10 )
229
229
230
+ def test_match_failure_string_quoting (self ):
231
+ with pytest .raises (AssertionError ) as excinfo :
232
+ with pytest .raises (AssertionError , match = "'foo" ):
233
+ raise AssertionError ("'bar" )
234
+ msg , = excinfo .value .args
235
+ assert msg == 'Pattern "\' foo" not found in "\' bar"'
236
+
230
237
def test_raises_match_wrong_type (self ):
231
238
"""Raising an exception with the wrong type and match= given.
232
239
You can’t perform that action at this time.
0 commit comments