Refs #32655 -- Improved error if iter_test_cases() is passed a string.
This commit is contained in:
parent
5371ad1d14
commit
8bca838f4a
|
@ -242,6 +242,13 @@ def iter_test_cases(tests):
|
|||
The tests argument can also be an iterable of TestCase objects.
|
||||
"""
|
||||
for test in tests:
|
||||
if isinstance(test, str):
|
||||
# Prevent an unfriendly RecursionError that can happen with
|
||||
# strings.
|
||||
raise TypeError(
|
||||
f'Test {test!r} must be a test case or test suite not string '
|
||||
f'(was found in {tests!r}).'
|
||||
)
|
||||
if isinstance(test, TestCase):
|
||||
yield test
|
||||
else:
|
||||
|
|
|
@ -36,7 +36,7 @@ class MySuite:
|
|||
yield from self.tests
|
||||
|
||||
|
||||
class TestSuiteTests(unittest.TestCase):
|
||||
class TestSuiteTests(SimpleTestCase):
|
||||
def build_test_suite(self, test_classes, suite=None, suite_class=None):
|
||||
if suite_class is None:
|
||||
suite_class = unittest.TestSuite
|
||||
|
@ -89,6 +89,14 @@ class TestSuiteTests(unittest.TestCase):
|
|||
'Tests1.test1', 'Tests1.test2', 'Tests2.test1', 'Tests2.test2',
|
||||
])
|
||||
|
||||
def test_iter_test_cases_string_input(self):
|
||||
msg = (
|
||||
"Test 'a' must be a test case or test suite not string (was found "
|
||||
"in 'abc')."
|
||||
)
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
list(iter_test_cases('abc'))
|
||||
|
||||
def test_iter_test_cases_iterable_of_tests(self):
|
||||
class Tests(unittest.TestCase):
|
||||
def test1(self):
|
||||
|
|
Loading…
Reference in New Issue