[Fixed]-How to assertRaises a django.contrib.auth.models.DoesNotExist exception?

1👍

You’re testing at the wrong level. Using the client to post to a view would never raise a Django exception; even if that exception is not caught within your view itself, which it almost certainly is, it would definitely be caught by the Django error middleware, and presented to the client as a 500 error.

So if you’re really not catching that exception you can check that the result from the post has status 500; otherwise you need to check for whatever message you are showing to the user that the model does not exist.

Leave a comment