Running and writing tests

Running the tests

You can run the tests with:


If you have Django installed, this will run the Django-specific tests. If you don’t, then the test runner will skip the Django-specific tests.


If you need to adjust the settings, copy to a new file (like, edit the file, and specify that as the value for the environment variable DJANGO_SETTINGS_MODULE.

DJANGO_SETTINGS_MODULE=test_settings_local ./

This is helpful if you need to change the value of ES_HOSTS to match the ip address or port that elasticsearch is listening on.

Writing tests

Tests are located in elasticutils/tests/.

We use nose for test utilities and running tests.


If you’re testing things in ElasticUtils that require hitting an ElasticSearch instance, then you should subclass elasticutils.tests.ElasticTestCase which has code in it for making things easier.

class elasticutils.tests.ElasticTestCase(methodName='runTest')

Superclass for ElasticSearch-using test cases.

  • index_name – string; name of the index to use
  • skip_tests – bool; if ElasticSearch isn’t available, then this is True and therefore tests should be skipped for this class

For examples of usage, see the other test_*.py files.

classmethod refresh(timesleep=0)

Refresh index after indexing.

This refreshes the index specified by self.index_name.

Parameters:timesleep – int; number of seconds to sleep after telling ES to refresh

Set up a single test.

Raises SkipTest:
 if skip_tests is True for this class/instance
classmethod setup_class()

Class setup for tests.

Checks to see if ES is running and if not, sets skip_test to True on the class.

classmethod teardown_class()

Class tear down for tests.

Project Versions

Table Of Contents

Previous topic


Next topic

Release process

This Page