Skip to main content
https://raw.githubusercontent.com/dbfixtures/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 fixtures.

Project Architecture Diagram

How to use

Prerequisites

Install Elasticsearch 8.x or newer following the official documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html

Quickstart: first test

  1. Install the plugin and your test dependencies (as you normally do for your project).

  2. Ensure Elasticsearch is available (local install or container).

  3. Create a test that uses the built-in fixture:

def test_can_connect(elasticsearch):
    assert elasticsearch.info()
  1. Run your tests:

pytest

The plugin contains three fixtures:

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

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

  • elasticsearch_nooproc - a no-process fixture that holds connection data to an already running Elasticsearch instance

Simply include one of these fixtures in your test fixture list.

You can also create additional Elasticsearch client and process fixtures if you 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 use already running Elasticsearch servers (e.g., in Docker). To connect to them, use the elasticsearch_nooproc fixture.

es_external = factories.elasticsearch('elasticsearch_nooproc')

Configure the host/port to match your running Elasticsearch instance using the options below. If not provided, the noprocess fixture defaults to port 9200.

If the server requires authentication, set either basic_auth or api_key, not both.

es_external_proc = factories.elasticsearch_noproc(
    host="localhost",
    port=9200,
    basic_auth=("elastic", "<your_password>"),
)
es_external = factories.elasticsearch("es_external_proc")

Credentials passed to the factory replace those from the command line or pytest.ini.

Configuration

You can define your settings in three ways: fixture factory arguments, command line options, and pytest.ini configuration options. 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

port (default 9200)

random (free port)

api_key

api_key

–elasticsearch-api-key

elasticsearch_api_key

api_key

user and password separated by ‘:’

basic_auth

–elasticsearch-basic-auth

elasticsearch_basic_auth

basic_auth

Free port search count

port_search_count

–elasticsearch-port-search-count

elasticsearch_port_search_count

5

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 to your own fixture

    elasticsearch_proc = factories.elasticsearch_proc(
        cluster_name='awsome_cluster')
  • specify your cluster name 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 the user running tests must have access to are:

  • /etc/default/elasticsearch

Make sure you either run tests as a user who has access to these files, or grant the user proper permissions or add them to the proper groups.

In CI, 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 6.1.0

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 6.1.0
File Size Uploaded Provenance Actions
pytest_elasticsearch-6.1.0.tar.gz 19.9 kB With provenance Details for pytest_elasticsearch-6.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-elasticsearch 6.1.0
File Interpreter ABI Platform Actions
pytest_elasticsearch-6.1.0-py3-none-any.whl Python 3 none any Details for pytest_elasticsearch-6.1.0-py3-none-any.whl

Total release size: 37.5 kB

Release files / pytest_elasticsearch-6.1.0.tar.gz

Download URL pytest_elasticsearch-6.1.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
08754de9c7ae4726e1a82118005d23521ea9564b53054aba32d3b3139b77e544
BLAKE2b-256 checksum
How to use checksums
573ce7b0b73b50644e9b3c718dd5719b80ba440ac9b052ba04465bfad747a3f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / pytest_elasticsearch-6.1.0-py3-none-any.whl

Download URL pytest_elasticsearch-6.1.0-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4545d146726ca58b412992a58a4122566ee883794631f9b767d0f54ae3a96739
BLAKE2b-256 checksum
How to use checksums
ac72cd1c47f6e6ab0c8794507c60de1f27c6ddc99135ef6bff9af1ee7cdfdd0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for pytest-elasticsearch 6.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_elasticsearch-6.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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