Issue #21578: Fixed misleading error message when ImportError called with

invalid keyword args.
This commit is contained in:
Serhiy Storchaka 2016-09-27 20:45:35 +03:00
parent c0b7037d4f
commit 47dee11ba7
3 changed files with 46 additions and 24 deletions

View file

@ -1096,6 +1096,23 @@ class ImportErrorTests(unittest.TestCase):
self.assertEqual(exc.name, 'somename')
self.assertEqual(exc.path, 'somepath')
msg = "'invalid' is an invalid keyword argument for this function"
with self.assertRaisesRegex(TypeError, msg):
ImportError('test', invalid='keyword')
with self.assertRaisesRegex(TypeError, msg):
ImportError('test', name='name', invalid='keyword')
with self.assertRaisesRegex(TypeError, msg):
ImportError('test', path='path', invalid='keyword')
with self.assertRaisesRegex(TypeError, msg):
ImportError(invalid='keyword')
msg = "'invalid|another' is an invalid keyword argument for this function"
with self.assertRaisesRegex(TypeError, msg):
ImportError('test', invalid='keyword', another=True)
def test_non_str_argument(self):
# Issue #15778
with check_warnings(('', BytesWarning), quiet=True):