diff --git a/django/test/utils.py b/django/test/utils.py index 1129976e4e..b6ab39901b 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -15,7 +15,7 @@ class ContextList(list): for subcontext in self: if key in subcontext: return subcontext[key] - raise KeyError + raise KeyError(key) else: return super(ContextList, self).__getitem__(key) diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index 42b763ca41..f3585268b3 100644 --- a/tests/regressiontests/test_client_regress/models.py +++ b/tests/regressiontests/test_client_regress/models.py @@ -602,6 +602,12 @@ class ContextTests(TestCase): self.assertEqual(response.context['request-foo'], 'whiz') self.assertEqual(response.context['data'], 'sausage') + try: + response.context['does-not-exist'] + self.fail('Should not be able to retrieve non-existent key') + except KeyError, e: + self.assertEquals(e.message, 'does-not-exist') + def test_inherited_context(self): "Context variables can be retrieved from a list of contexts" response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'}) @@ -611,6 +617,13 @@ class ContextTests(TestCase): self.assertEqual(response.context['request-foo'], 'whiz') self.assertEqual(response.context['data'], 'bacon') + try: + response.context['does-not-exist'] + self.fail('Should not be able to retrieve non-existent key') + except KeyError, e: + self.assertEquals(e.message, 'does-not-exist') + + class SessionTests(TestCase): fixtures = ['testdata.json']