mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
1ed2e69a4a
commit
f920c2122b
5 changed files with 70 additions and 9 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue