Skip to main content

Elasticsearch process and client fixtures for py.test.

Project description


Latest PyPI version Wheel Status Supported Python Versions License

Package status

Tests Coverage Status Requirements Status

What is this?

This is a pytest plugin, that enables you test your code that relies on an Elasticsearch search engine. It allows you to specify fixtures for Elasticsearch process and client.

How to use

Warning This fixture requires at least version 1.0 of elasticsearch to work.

You can set and run elasticsearch process with your own settings (i.e. use random port or define your own logsdir)

elasticsearch_proc = factories.elasticsearch_proc(
    port=None, logsdir='/tmp')

You can use elasticsearch client fixture to run your test. (Remember that client fixture requires a process fixture to work properly.)

elasticsearch = factories.elasticsearch(elasticsearch_proc)

To check if everything is ready to go, you can always test both fixtures:

def test_elastic_process(elasticsearch_proc):
    """Simple test for starting elasticsearch_proc."""
    assert elasticsearch_proc.running() is True

def test_elasticsarch(elasticsearch):
    """Tests if elasticsearch fixtures connects to process."""

    info =
    assert info['status'] == 200


You can define your settings in three ways, it’s fixture factory argument, command line option and pytest.ini configuration option. You can pick which you prefer, but remember that these settings are handled in the following order:

  • Fixture factory argument
  • Command line option
  • Configuration option in your pytest.ini file
Elasticsearch option Fixture factory argument Command line option Configuration option in pytest.ini Default
logs directory logsdir –elasticsearch-logsdir elasticsearch_logsdir /tmp
host host –elasticsearch-host elasticsearch_host
port port –elasticsearch-port elasticsearch_port 9201
cluster_name cluster_name –elasticsearch-cluster-name elasticsearch_cluster_name elasticsearch_cluster_9201
index store type index_store_type –elasticsearch-index-store-type elasticsearch_index_store_type memory
network publish host network_publish_host –elasticsearch-network-publish-host elasticsearch_network_publish_host
logs prefix logs_prefix –elasticsearch-logs-prefix elasticsearch_logs_prefix  
discovery en ping multicast enabled discovery_zen_ping_multicast_enabled –elasticsearch-discovery-zen-ping-multicast-enabled elasticsearch_discovery_zen_ping_multicast_enabled False
Example of use: logs directory:
  • pass it as an argument in your own fixture

    elasticsearch_proc = factories.elasticsearch_proc(
  • use --elasticsearch-logsdir command line option when you run your tests

    py.test tests --elasticsearch-logsdir=/tmp
  • specify your directory as logsdir in your pytest.ini file.

    To do so, put a line like the following under the [pytest] section of your pytest.ini:

    elasticsearch_logsdir =

If you don’t want to define your own settings in any given way, you can always use a default values.


After creating package on github, move to, and turn on ci builds for given package.



  • [feature] pytest.ini option for every command line option
  • [feature] Command line options for every fixture factory argument
  • Extracted original code from pytest-dbfixtures

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 pytest-elasticsearch, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size pytest_elasticsearch-1.0.0-py2.7.egg (14.5 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size pytest_elasticsearch-1.0.0-py2.py3-none-any.whl (12.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pytest-elasticsearch-1.0.0.tar.gz (30.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page