I’m trying to create a UnitTest to verify that an object has been deleted.
from django.utils import unittest
def test_z_Kallie_can_delete_discussion_response(self):
...snip...
self._driver.get("http://localhost:8000/questions/3/want-a-discussion")
self.assertRaises(Answer.DoesNotExist, Answer.objects.get(body__exact = '<p>User can reply to discussion.</p>'))
I keep getting the error:
DoesNotExist: Answer matching query does not exist.
You don’t need to import it – as you’ve already correctly written,
DoesNotExistis a property of the model itself, in this caseAnswer.Your problem is that you are calling the
getmethod – which raises the exception – before it is passed toassertRaises. You need to separate the arguments from the callable, as described in the unittest documentation:or better: