Elasticsearch process and client fixtures for py.test.
Project description
pytest-elasticsearch
Package status
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, logsdir='/tmp')
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:
Fixture factory argument
Command line option
Configuration option in your pytest.ini file
ElasticSearch option |
Fixture factory argument |
Command line option |
pytest.ini option |
Noop process fixture |
Default |
---|---|---|---|---|---|
logs directory |
logsdir |
–elasticsearch-logsdir |
elasticsearch_logsdir |
$TMPDIR |
|
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 |
|
logs prefix |
logs_prefix |
–elasticsearch-logs-prefix |
elasticsearch_logs_prefix |
||
transport tcp port |
transport_tcp_port |
–elasticsearch-transport-tcp-port |
elasticsearch_transport_tcp_port |
random |
|
configuration path |
configuration_path |
–elasticsearch-configuration-path |
elasticsearch_configuration_path |
/etc/elasticsearch |
Example usage:
pass it as an argument in your own fixture
elasticsearch_proc = factories.elasticsearch_proc( cluster_name='awsome_cluster)
use --elasticsearch-logsdir command line option when you run your tests
py.test tests --elasticsearch-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
Package resources
CHANGELOG
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file pytest_elasticsearch-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: pytest_elasticsearch-2.0.1-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74a2885fc65a1c25e725c500783ec5969859f1e3cb72b103ba4ee451ee676839 |
|
MD5 | e640e43647cd900b84785ac751e2c1b2 |
|
BLAKE2b-256 | 079e45a6a755166a2dfccafd56b18f3cca99298646dcf3a2ae54f58c9ef92b0f |