I have this function that I want to test:
def get_django_model(django_model):
try:
app_config = apps.get_app_config("myapp")
model = app_config.get_model(django_model)
return model
except Exception:
raise DjangoModelMissing(f"Missing django model: {django_model}")
And here is my test:
class ModelInstanceTest(TestCase):
def test_get_django_model(self):
model_class = get_djagno_model("Foo")
self.assertIsInstance(model_class, models.Foo)
The above test fails, saying AssertionError: <class 'models.Foo'> is not an instance of <class 'models.Foo'>.
However if I replace assertIsInstance with assertIs the test passes.
Can someone explain what is going on here?
This post is related, but doesn't really explain the different results: Python test to check instance type.
get_djagno_model(django)