Skip to content

Commit c353cf1

Browse files
gh-125038: Test improvement, assertRaisesRegex is used
1 parent d3d5b39 commit c353cf1

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

Lib/test/test_generators.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,9 @@ def get_generator():
274274
g.gi_frame.f_locals['.0'] = range(20)
275275
return g
276276

277-
def genexpr_to_list():
278-
try:
279-
l = list(get_generator())
280-
return "NoError"
281-
except TypeError:
282-
return "TypeError"
283-
284-
# This should not raise
285-
r = genexpr_to_list()
286-
287-
self.assertIs(r, "TypeError")
277+
err_msg = "'for' requires an object with __iter__ method, got range"
278+
with self.assertRaisesRegex(TypeError, err_msg):
279+
l = list(get_generator())
288280

289281
class ExceptionTest(unittest.TestCase):
290282
# Tests for the issue #23353: check that the currently handled exception

0 commit comments

Comments
 (0)