Skip to main content

Automatically sets up an elasticsearch instance in a temporary directory, and destroys it after testing

Project description

testing.elasticsearch automatically sets up an elasticsearch instance in a temporary directory, and destroys it after testing. It’s useful as a pytest fixture for testing interactions with elasticsearch in an isolated manner.

Implementation is based off the awesome testing.redis module.

Example usage:

import testing.elasticsearch
import pyes.es import ES

# launch new elasticsearch server:
with testing.elasticsearch.ElasticSearchServer() es:
    elasticsearch = ES(es.uri())
    # perform any testing with elasticsearch here

# elasticsearch server is terminated and cleaned up here

You can change the server configuration by specifying a config dict:

with ElasticSearchServer(config={
    'logger.level': 'DEBUG',
    # Keep index in memory
    'index.store.type': 'mmapfs',
}) as es:
    ...

…or by setting them on the config attribute before starting the server:

es = ElasticSearchServer()
es.config['logger.level'] = 'DEBUG'
es.start()

You can also setup a pytest fixture:

@pytest.fixture(scope='session')
def elasticsearch(request):
    """
    A testing fixture that provides a running elasticsearch server.
    """
    es = ElasticSearchServer()
    es.start()
    request.addfinalizer(es.stop)
    return es

Testing

To run tests you’ll need to install the test requirements:

pip install -r src/tests/requirements.txt

Run tests:

python src/tests/runtests.py

Project details


Download files

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

Files for testing.elasticsearch, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size testing.elasticsearch-0.3.0-py2-none-any.whl (6.1 kB) File type Wheel Python version 2.7 Upload date Hashes View hashes
Filename, size testing.elasticsearch-0.3.0.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View hashes

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