In the unittest
style, I can test that a page uses a particular template by calling assertTemplateUsed
. This is useful, for example, when Django inserts values through a template, so that I can't just test string equality.
How should I write the equivalent statement in pytest?
I've been looking in pytest-django but don't see how to do it.
As phd stated in a comment, use the following to assert that a template file is actually used in a view:
Update: Since v3.8.0 (2020-01-14) pytest-django makes all of the assertions in Django's TestCase available in
pytest_django.asserts
. See Stan Redoute's answer for an example.