Fixed #20321 -- Added missing key name in MergeDict KeyError message

Thanks mark.harviston et gmail.com for the report.
This commit is contained in:
Claude Paroz 2013-04-26 08:57:39 +02:00
parent 6bccbc05a4
commit 4769db6b5f
2 changed files with 9 additions and 1 deletions

View File

@ -26,7 +26,7 @@ class MergeDict(object):
return dict_[key]
except KeyError:
pass
raise KeyError
raise KeyError(key)
def __copy__(self):
return self.__class__(*self.dicts)

View File

@ -209,6 +209,14 @@ class MergeDictTests(SimpleTestCase):
self.assertFalse(empty)
self.assertTrue(not_empty)
def test_key_error(self):
"""
Test that the message of KeyError contains the missing key name.
"""
d1 = MergeDict({'key1': 42})
with six.assertRaisesRegex(self, KeyError, 'key2'):
d1['key2']
class MultiValueDictTests(SimpleTestCase):