Skip to main content

Elasticsearch process and client fixtures for py.test.

Project description

pytest-elasticsearch

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 = elasticsearch.info()
    assert info['status'] == 200

Configuration

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

127.0.0.1

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

127.0.0.1

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 of use: logs directory:

  • pass it as an argument in your own fixture

    elasticsearch_proc = factories.elasticsearch_proc(
        logsdir='/tmp')
  • 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:

    [pytest]
    elasticsearch_logsdir =
      /tmp/elasticsearch/logs

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

Package resources

Travis-ci

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

CHANGELOG

1.1.0

  • [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

1.0.0

  • [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.

Source Distribution

pytest-elasticsearch-1.1.0.tar.gz (30.6 kB view details)

Uploaded Source

Built Distributions

pytest_elasticsearch-1.1.0-py2.py3-none-any.whl (12.6 kB view details)

Uploaded Python 2 Python 3

pytest_elasticsearch-1.1.0-py2.7.egg (15.1 kB view details)

Uploaded Source

File details

Details for the file pytest-elasticsearch-1.1.0.tar.gz.

File metadata

File hashes

Hashes for pytest-elasticsearch-1.1.0.tar.gz
Algorithm Hash digest
SHA256 79fc0e6683d806e2bce472498cc351f45c3b690112eca04e5ce9138cb3a5b1c1
MD5 64465afa547fcdb9e490f287dd7d1fb4
BLAKE2b-256 d0d38682777e49b9787ba7716843ad1b170a4c4c96d9bcd69a2331983063bc8b

See more details on using hashes here.

File details

Details for the file pytest_elasticsearch-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_elasticsearch-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d76419c744da31d4b9d80a636aad11e63e100adcb0c3e379d4716c91ceecaf25
MD5 9eee00932febc40e97430aaead42b8ea
BLAKE2b-256 ee91d61f53bdbadbbf462100a1dc459c959e6a2e5934cdb607e14a4951474dbc

See more details on using hashes here.

File details

Details for the file pytest_elasticsearch-1.1.0-py2.7.egg.

File metadata

File hashes

Hashes for pytest_elasticsearch-1.1.0-py2.7.egg
Algorithm Hash digest
SHA256 3caa48505fa824330cc3c3d577f5e2dd6b17fa1b9447b659a38527431d8c508f
MD5 0d4a5023078760850badde5d608a28f0
BLAKE2b-256 86dfb2d083670f534faed9b0f3c8411f53f1bef8c821c8721ca909c91eb340aa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page