You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When rendering templates in Django the template engine will use callable() to decide whether to call a variable to resolve a value. When testing using a Fake object this results in an exception:
RuntimeError: fake:StatusPage object cannot be called (maybe you want Fake.is_callable() ?)
This is because Fake.__call__ is declared even though the fake is not expected to be called, so callable(fake) is alwaysTrue and the template engine will try to call it.
Took me a while to realise this and come up with a workaround, which is to make sure the fake is callable and just returns itself so the template engine resolves it to itself:
my_fake.expects_call().returns(my_fake)
I'm not sure this is a bug, but I think it's something worth highlighting in the documentation. The documentation doesn't seem to be searchable, but I had a skim through and couldn't find a reference to callable().
The text was updated successfully, but these errors were encountered:
This path was added when Django converted User.is_authenticated from a method to a boolean. Maybe this can help make a callable Fake that Django doesn't call in templates.
When rendering templates in Django the template engine will use
callable()
to decide whether to call a variable to resolve a value. When testing using aFake
object this results in an exception:This is because
Fake.__call__
is declared even though the fake is not expected to be called, socallable(fake)
is alwaysTrue
and the template engine will try to call it.Took me a while to realise this and come up with a workaround, which is to make sure the fake is callable and just returns itself so the template engine resolves it to itself:
I'm not sure this is a bug, but I think it's something worth highlighting in the documentation. The documentation doesn't seem to be searchable, but I had a skim through and couldn't find a reference to
callable()
.The text was updated successfully, but these errors were encountered: