Elastic Connect supplies a set of convinience options and fixtures for testing with pytest. To use these features just

import elastic_connect.testing

in your tests or preferably conftest.py. This automatically uses some fixtures, makes available others and adds custom options for running the tests.


Don’t clear the indices. Debugging only, may break some tests.
--es-host, default="localhost"
Elasticsearch hostname
--es-port, default="9200"
Elasticsearch port
--es-prefix, default="test"
Elasticsearch indices prefix
--namespace, default=False
Also run tests for two namespaces

Autouse Fixtures


@pytest.fixture(scope=”session”, autouse=True)

Fixes the default connection to elasticsearch according to --es-host and --es-port options. Waits for all namespaces to be ready. :yield: None


@pytest.fixture(scope=”session”, autouse=True)

Set the prefix for all indices according to --es-prefix option, just to be safe. So with the default option a model which uses index admin_users in production will use index testadmin_users in the tests.


elastic_connect.testing.fix_index(request, model_classes)[source]


Creates indices for supplied model_classes. Deletes these indices after the tests according to the --index-noclean option.

Parameters:model_classes – list of model classes


Returns the Namespace object of a second elasticsearch cluster. This cluster must be available on localhost:18400. You may use this fixture as a base for your own connections to multiple elasticsearch clusters. :return: Namespace