Skip to main content
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

Metadata

Release files for pytest-elasticsearch-test 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-elasticsearch-test 0.0.3
File Size Uploaded
pytest_elasticsearch_test-0.0.3.tar.gz 28.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-elasticsearch-test 0.0.3
File Interpreter ABI Platform
pytest_elasticsearch_test-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 54.8 kB

Release files / pytest_elasticsearch_test-0.0.3.tar.gz

Download URL pytest_elasticsearch_test-0.0.3.tar.gz
Size 28.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fa9a2dfa3929e3beed560c0c6471d99c0b3ab0fad9a9ef0135049199ab589281
BLAKE2b-256 checksum
How to use checksums
d0f0d33d4f919eef9ddc05509364a99418fb1595b82d17696979c48ba848ef35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / pytest_elasticsearch_test-0.0.3-py3-none-any.whl

Download URL pytest_elasticsearch_test-0.0.3-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55bc4b4023ce35c509df5fb8da9cb40aa7d44231eebcc52ac7d1f1aa1b370b21
BLAKE2b-256 checksum
How to use checksums
e04e4d1c295a81a06913d363e9594d5a5316b9fc2286abf166e1da54cc420f4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page