Skip to content

Commit 66c305d

Browse files
committed
assertRaisesRegex exact match
1 parent 6e3d282 commit 66c305d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Lib/test/test_functools.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from itertools import permutations
77
import pickle
88
from random import choice
9+
import re
910
import sys
1011
from test import support
1112
import threading
@@ -361,16 +362,16 @@ def test_setstate(self):
361362
f = self.partial(signature)
362363
f.__setstate__((capture, (PH, 1), dict(a=10), dict(attr=[])))
363364
self.assertEqual(signature(f), (capture, (PH, 1), dict(a=10), dict(attr=[])))
364-
msg_regex = ("^missing positional arguments in 'partial' call; "
365-
"expected at least 1, got 0$")
366-
with self.assertRaisesRegex(TypeError, msg_regex) as cm:
365+
msg_regex = re.escape("missing positional arguments in 'partial' call; "
366+
"expected at least 1, got 0")
367+
with self.assertRaisesRegex(TypeError, f'^{msg_regex}$') as cm:
367368
f()
368369
self.assertEqual(f(2), ((2, 1), dict(a=10)))
369370

370371
# Trailing Placeholder error
371372
f = self.partial(signature)
372-
msg_regex = "^trailing Placeholders are not allowed$"
373-
with self.assertRaisesRegex(TypeError, msg_regex) as cm:
373+
msg_regex = re.escape("trailing Placeholders are not allowed")
374+
with self.assertRaisesRegex(TypeError, f'^{msg_regex}$') as cm:
374375
f.__setstate__((capture, (1, PH), dict(a=10), dict(attr=[])))
375376

376377
def test_setstate_errors(self):

0 commit comments

Comments
 (0)