diff options
author | Robert Collins <rbtcollins@hp.com> | 2014-10-20 00:24:05 (GMT) |
---|---|---|
committer | Robert Collins <rbtcollins@hp.com> | 2014-10-20 00:24:05 (GMT) |
commit | f920c2122b86857f6c6b61ba857ba5f51dccf7d0 (patch) | |
tree | 2984e2d2ee149bbc36bd7f8be2881ca392e664d5 /Lib/unittest/test/test_discovery.py | |
parent | 1ed2e69a4ac1a4ac5a83ce3ab332b3051eaf59f0 (diff) | |
download | cpython-f920c2122b86857f6c6b61ba857ba5f51dccf7d0.zip cpython-f920c2122b86857f6c6b61ba857ba5f51dccf7d0.tar.gz cpython-f920c2122b86857f6c6b61ba857ba5f51dccf7d0.tar.bz2 |
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.
Diffstat (limited to 'Lib/unittest/test/test_discovery.py')
-rw-r--r-- | Lib/unittest/test/test_discovery.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_discovery.py b/Lib/unittest/test/test_discovery.py index da206fd..92b983a 100644 --- a/Lib/unittest/test/test_discovery.py +++ b/Lib/unittest/test/test_discovery.py @@ -399,6 +399,13 @@ class TestDiscovery(unittest.TestCase): suite = loader.discover('.') self.assertIn(os.getcwd(), sys.path) 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 import test module: test_this_does_not_exist' in error, + 'missing error string in %r' % error) test = list(list(suite)[0])[0] # extract test from suite with self.assertRaises(ImportError): @@ -418,6 +425,13 @@ class TestDiscovery(unittest.TestCase): self.assertIn(abspath('/foo'), sys.path) 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 import test module: my_package' in error, + 'missing error string in %r' % error) test = list(list(suite)[0])[0] # extract test from suite with self.assertRaises(ImportError): test.my_package() |