[Answer]-Testing content of Django.contrib.messages for invalid forms

1👍

Two things you could check:

  1. When you create the request self.client.post(url, {"name": ""}) is a Thing instance returned here: thing = Thing.objects.get(id=thing_id) If not it will not reach the line of code where you set your error message: messages.error(request, "Oops!") as Thing.objects.get will throw an error.

If there are no results that match the query, get() will raise a
DoesNotExist exception.

  1. If the first thing does return a Thing instance, you could check whether a redirect return redirect("/wherever") after setting the error message messages.error(request, "Oops!") does change anything.

Leave a comment