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

CHANGELOG

3.0.0

Features

  • Import FixtureRequest from pytest, not private _pytest. Require at least pytest 6.2

  • Replace tmpdir_factory with tmp_path_factory

Removals

  • Removed logs_prefix process fixture parameter, –elasticsearch-logsdir command parameter and elasticsearch_logsdir ini configuration option

  • Removed elasticsearch_logsdir process fixture parameter –elasticsearch-logs-prefix command parameter and elasticsearch_logs_prefix ini configuration option

Support

  • support only elasticsearch 6.x and up, same as the most recent elasticsearch library

Misc

  • rely on get_port functionality delivered by port_for

2.1.0

Features

  • Add command line and ini configuration option for the executable.

  • Require python 3.7 and up

  • Unify handling of a temporary directory, now temporary directory holding logs, workdir, pid will be named after fixture name.

Deprecations

  • Deprecated logs_prefix process fixture parameter, –elasticsearch-logsdir command parameter and elasticsearch_logsdir ini configuration option

  • Deprecated elasticsearch_logsdir process fixture parameter –elasticsearch-logs-prefix command parameter and elasticsearch_logs_prefix ini configuration option

Bugfix

  • Handle properly elasticsearch versions with two-digit minor version

Misc

  • Migrated CI/CD to Github Actions

  • Blackified Codebase

2.0.1

  • [cleanup] Drop support for python versions older than 3.6

  • [fix] Adjust for mirakuru 2.2.0 and up

2.0.0

  • [enhancement] Created a specified Executor to manage elasticsearch

  • [enhancement] added new elasticsearch_nooproc fixture to connect to already existing elasticsearch index

  • [cleanup] Drop support for unused discovery_zen_ping_multicast and elasticsearch_configuration_path option

  • [cleanup] Drop support for elasticsearch older than 5

  • [cleanup] Drop support for python versions older than 3.5

  • [bugfix] changed default index.memory type to mmapfs, over long invalid memory type

1.3.0

  • [feature] - Support for major elasticsearch versions

1.2.1

  • [cleanup] - removed path.py dependency

1.2.0

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

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

Uploaded Source

Built Distribution

pytest_elasticsearch-3.0.0-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-elasticsearch-3.0.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytest-elasticsearch-3.0.0.tar.gz
Algorithm Hash digest
SHA256 9d076814e2219e8a71031f2bcfcc85dfd4519c1d0054afc4a0237df90eff1920
MD5 b1acc4b835354fd3541e16048c6d5cb6
BLAKE2b-256 b00f29c0ab8dca75bc6348960b289eeec600562cc88acd615eaa6176c1c788c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_elasticsearch-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytest_elasticsearch-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e61902107a1076604c3af3b25458e49f111f1451fa05d1b76f093ce05f337dc5
MD5 8d43870eb26ca85d3698cd15b33a3101
BLAKE2b-256 fe74354c6984e8c0e54bdb82621d7da09db8e0f60f492d86225592463593699e

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