Skip to main content

automatically setups a elasticsearch instance in a temporary directory, and destroys it after testing

Project description


testing.elasticsearch automatically setups a elasticsearch instance in a temporary directory, and destroys it after testing.


Use pip:

$ pip install testing.elasticsearch2

And testing.elasticsearch2 requires Elasticsearch server in your PATH.


Create Elasticsearch instance using testing.elasticsearch.Elasticsearch:

import testing.elasticsearch
from sqlalchemy import create_engine

# Lanuch new Elasticsearch server
with testing.elasticsearch.Elasticsearch() as elasticsearch:
    # connect to Elasticsearch (using elasticsearch-py)
    es = Elasticsearch(**elasticsearch.dsn())

    # do any tests using Elasticsearch...

# Elasticsearch server is terminated here

testing.elasticsearch.Elasticsearch generates temporary config files and data directories. On deleting Elasticsearch object, it terminates Elasticsearch instance and removes temporary files and directories.

If you want a database including indexes and any fixtures for your apps, use copy_data_from keyword:

# uses a copy of specified data directory of Elasticsearch.
elasticsearch = testing.elasticsearch.Elasticsearch(copy_data_from='/path/to/your/index')

For example, you can setup new Elasticsearch server for each testcases on setUp() method:

import unittest
import testing.elasticsearch

class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.elasticsearch = testing.elasticsearch.Elasticsearch()

    def tearDown(self):


  • Python 2.7, 3.3, 3.4, 3.5


Apache License 2.0


1.0.0 (2016-08-20)

  • Drop python 2.6, 3.2 support
  • Depend on testing.common.database >= 2.0.0
  • Set booting timeout to 20sec
  • Fix bugs:
    • #1: find_elasticsearch_yaml_path() does not refer elasticsearch_home argument
    • #2: Make ES_PATH absolute

0.9.1 (2016-02-04)

  • Depend on testing.common.database package

0.9.0 (2015-12-13)

  • First release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
testing.elasticsearch2-1.0.0-py2.py3-none-any.whl (7.3 kB) Copy SHA256 hash SHA256 Wheel 2.7
testing.elasticsearch2-1.0.0.tar.gz (9.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page