Closed jdotjdot closed 6 years ago
Hi @jdotjdot, thanks for the feedback!
Indeed, this is something we didn't cover until now. I pushed an update to our demo app to showcase how you can turn off algoliasearch-django
in your tests:
Update your settings.py
to add a setting for when tests are running:
import sys
TESTING = sys.argv[1:2] == ['test']
In your AppConfig
, only register Algolia when you are not testing:
if not settings.TESTING:
algoliasearch.register(Contact, ContactIndex)
With this approach, you won't have algolia registered when running your tests. This should solve your issue, but if it persists please reopen this ticket and let me know what's happening!
How do we turn off
algoliasearch-django
for tests? The way signals are registered, and the registration of models to the engine inapps.py
has been breaking our test suite--we need a simple way to turn Algolia indexing on and off within tests with just a simple setting.Is there any way to do this? The only way I can see is the
with self.settings(...)
modification in the docs, which isn't simple but also doesn't seem to work when we tried it. We either get items indexing, or we get error issues that a model is already registered when we try to just remove theINSTALLED_APPS
entirely.By using the
with self.settings(...)
method and turning'AUTO_INDEXING'
toFalse
, we're actually getting aRegistrationError
that the model isn't registered with the Algolia engine now. I want Algolia code not to be firing at all during this test, so I'm not sure why this is happening.