Close #19746: expose unittest discovery errors on TestLoader.errors

This makes it possible to examine the errors from unittest discovery
without executing the test suite - important when the test suite may
be very large, or when enumerating the test ids from a test suite.
This commit is contained in:
Robert Collins 2014-10-20 13:24:05 +13:00
parent 1ed2e69a4a
commit f920c2122b
5 changed files with 70 additions and 9 deletions

View file

@ -24,6 +24,13 @@ def warningregistry(func):
class Test_TestLoader(unittest.TestCase):
### Basic object tests
################################################################
def test___init__(self):
loader = unittest.TestLoader()
self.assertEqual([], loader.errors)
### Tests for TestLoader.loadTestsFromTestCase
################################################################
@ -336,6 +343,13 @@ class Test_TestLoader(unittest.TestCase):
suite = loader.loadTestsFromModule(m)
self.assertIsInstance(suite, unittest.TestSuite)
self.assertEqual(suite.countTestCases(), 1)
# Errors loading the suite are also captured for introspection.
self.assertNotEqual([], loader.errors)
self.assertEqual(1, len(loader.errors))
error = loader.errors[0]
self.assertTrue(
'Failed to call load_tests:' in error,
'missing error string in %r' % error)
test = list(suite)[0]
self.assertRaisesRegex(TypeError, "some failure", test.m)