Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Elasticsearch process and client fixtures for py.test.

Project Description


Package status

What is this?

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

How to use


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

Plugin contains two fixtures

  • elasticsearch - it’s a client fixture that has functional scope, and which cleans Elasticsearch at the end of each test.
  • elasticsearch_proc - session scoped fixture, that starts Elasticsearch instance at it’s first use and stops at the end of the tests.

Simply include one of these fixtures into your tests fixture list.

You can also create additional elasticsearch client and process fixtures if you’d need to:

from pytest_elasticsearch import factories

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


Each elasticsearch process fixture can be configured in a different way than the others through the fixture factory arguments.


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 pytest.ini option Default
logs directory logsdir –elasticsearch-logsdir elasticsearch_logsdir $TMPDIR
host host –elasticsearch-host elasticsearch_host
port port –elasticsearch-port elasticsearch_port random
cluster_name cluster_name –elasticsearch-cluster-name elasticsearch_cluster_name elasticsearch_cluster_<port>
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  
enable zen discovery discovery_zen_ping_multicast_enabled –elasticsearch-discovery-zen-ping-multicast-enabled elasticsearch_discovery_zen_ping_multicast_enabled False

Example usage:

  • 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-cluster-name=awsome_cluster
  • specify your directory as elasticsearch_cluster_name in your pytest.ini file.

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

    elasticsearch_cluster_name = awsome_cluster



  • [cleanup] - removed dependency


  • [feature] - migrate usage of getfuncargvalue to getfixturevalue. require at least pytest 3.0.0
  • [feature] - default logsdir to $TMPDIR
  • [feature] - run process on random port by default - enhances xdist experience


  • [feature] use tmpfile.gettempdir instead of hardcoded /tmp directory
  • [docs] added description to all command line and ini options
  • [bugfix] made command line option’s dests more distinc, to prevent from influencing other pytest plugins


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

Release History

This version
History Node


History Node


History Node


History Node


History Node


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
(15.1 kB) Copy SHA256 Hash SHA256
Egg 2.7 Jan 25, 2017
(12.6 kB) Copy SHA256 Hash SHA256
Wheel py2.py3 Jan 25, 2017
(30.6 kB) Copy SHA256 Hash SHA256
Source None Jan 25, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting