Skip to main content

Elasticsearch fixtures and fixture factories for Pytest.

Project description

https://raw.githubusercontent.com/ClearcodeHQ/pytest-elasticsearch/master/logo.png

pytest-elasticsearch

Latest PyPI version Wheel Status Supported Python Versions License

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

The plugin contains two fixtures:

  • elasticsearch - a client fixture that has functional scope, and which cleans Elasticsearch at the end of each test.

  • elasticsearch_proc - a session scoped fixture, that starts Elasticsearch instance at its first use and stops at the end of the tests.

  • elasticsearch_nooproc - a nooprocess fixture, that’s holds connection data to already running elasticsearch

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)
elasticsearch_my = factories.elasticsearch('elasticsearch_my_proc')

Connecting to already existing Elasticsearch service

Some projects are using already running Elasticsearch servers (ie on docker instances). In order to connect to them, one would be using the elasticsearch_nooproc fixture.

es_external = factories.elasticsearch('elasticsearch_nooproc')

By default the elasticsearch_nooproc fixture would connect to elasticsearch instance using 9300 port.

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:

  1. Fixture factory argument

  2. Command line option

  3. Configuration option in your pytest.ini file

Configuration options

ElasticSearch option

Fixture factory argument

Command line option

pytest.ini option

Noop process fixture

Default

Elasticsearch executable

executable

–elasticsearch-executable

elasticsearch_executable

/usr/share/elasticsearch/bin/elasticsearch

host

host

–elasticsearch-host

elasticsearch_host

host

127.0.0.1

port

port

–elasticsearch-port

elasticsearch_port

6300

random

Elasticsearch cluster name

cluster_name

–elasticsearch-cluster-name

elasticsearch_cluster_name

elasticsearch_cluster_<port>

index storage type

index_store_type

–elasticsearch-index-store-type

elasticsearch_index_store_type

mmapfs

network publish host

network_publish_host

–elasticsearch-network-publish-host

elasticsearch_network_publish_host

127.0.0.1

transport tcp port

transport_tcp_port

–elasticsearch-transport-tcp-port

elasticsearch_transport_tcp_port

random

Example usage:

  • pass it as an argument in your own fixture

    elasticsearch_proc = factories.elasticsearch_proc(
        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:

    [pytest]
    elasticsearch_cluster_name = awsome_cluster

Known issues

It might happen, that the process can’t be started due to lack of permissions. The files that user running tests has to have access to are:

  • /etc/default/elasticsearch

Make sure that you either run tests as a user that has access to these files, or you give user proper permissions or add it to proper user groups.

In CI at the moment, we install elasticsearch from tar/zip archives, which do not set up additional permission restrictions, so it’s not a problem on the CI/CD.

Package resources

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-4.1.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

pytest_elasticsearch-4.1.0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-elasticsearch-4.1.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pytest-elasticsearch-4.1.0.tar.gz
Algorithm Hash digest
SHA256 0271d57a7c3bd4712643e4a32a9210739d7ae4c0ca804dbd08717cb560b85949
MD5 0fc81ead25706ae3f048de2d9abdd8fe
BLAKE2b-256 ef1bd51a169c110b654097f27abe63f47310aa67ba4e66932f75500fffdbc191

See more details on using hashes here.

File details

Details for the file pytest_elasticsearch-4.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_elasticsearch-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f8250cd9ea70316ec19051da20d8e8660c7fd7f11be9e788f134404a2fa0db0
MD5 b061f5a28e5ef7c66fe4022979a16042
BLAKE2b-256 2cc0ded5cb2fd25a30c9e5e93916e9a831a001190b1c81f0805d87a4b72081ed

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