Is it possible to disable haystack django for some tests?

We use django-haystack as our search index. In general, it’s great, but during tests it adds overhead for each creation and saving of the model object, and for most tests it is not required. Therefore, I would like to avoid this. So I decided to use override_settings to use a mannequin that did nothing. But now I tried both BaseSignalProcessor and SimpleEngine , and I still see that our search index (elasticsearch) has been badly damaged.

The two versions I tried are the following:

First use SimpleEngine , which does not create data:

 from django.test import TestCase from django.test.utils import override_settings HAYSTACK_DUMMY_INDEX = { 'default': { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', } } @override_settings(HAYSTACK_CONNECTIONS=HAYSTACK_DUMMY_INDEX) class TestAllTheThings(TestCase): # ... 

and then using BaseSignalProcessor , which should mean that the signals to save are not connected:

 from django.test import TestCase from django.test.utils import override_settings @override_settings(HAYSTACK_SIGNAL_PROCESSOR='haystack.signals.BaseSignalProcessor') class TestAllTheThings(TestCase): # ... 

I use pytest as a test runner in case that matters.

Any idea if something is missing me?

+5
source share

Source: https://habr.com/ru/post/1233647/


All Articles