In a Django project I'm working on I import a form in the view as follows
#views.py
from forms import SomeForm
then in a test file I have
#form_test.py
from app.forms import SomeForm
.
.
.
self.assertTrue(isinstance(response.context['form'], SomeForm))
Why doesn't the isinstance work?
If I inspect the output of type() for the two objects I get this:
response.context form: Expected form:
I can fix this by making my import mechanism in views.py match that in the form_test.py, but this seems like the wrong approach.
for reference, file structure as follows:
- site/
- manage.py
- app/
- forms.py
- views.py
- tests/
- form_test.py
isinstance
also compare module location,response.context['form']
class' module isforms
where SomeForm module isapp.forms
you check this by inspecting respectively__class__.__module__
and__module__
.To make isinstance work you can: