https://github.com/jong/testing.elasticsearch
Automatically sets up an elasticsearch instance in a temporary directory, and destroys it after testing.
https://github.com/jong/testing.elasticsearch
Last synced: 11 months ago
JSON representation
Automatically sets up an elasticsearch instance in a temporary directory, and destroys it after testing.
- Host: GitHub
- URL: https://github.com/jong/testing.elasticsearch
- Owner: jong
- License: mit
- Created: 2015-03-20T18:38:56.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-05-16T22:35:02.000Z (over 9 years ago)
- Last Synced: 2025-02-28T03:14:18.612Z (12 months ago)
- Language: Python
- Size: 23.4 KB
- Stars: 12
- Watchers: 3
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
testing.elasticsearch
=====================
`testing.elasticsearch` automatically sets up an elasticsearch instance in a
temporary directory, and destroys it after testing. It's useful as a pytest
fixture for testing interactions with elasticsearch in an isolated manner.
Implementation is based off the awesome `testing.redis `_ module.
Example usage:
.. code-block:: python
import testing.elasticsearch
import pyes.es import ES
# launch new elasticsearch server:
with testing.elasticsearch.ElasticSearchServer() es:
elasticsearch = ES(es.uri())
# perform any testing with elasticsearch here
# elasticsearch server is terminated and cleaned up here
You can change the server configuration by specifying a `config` dict:
.. code-block:: python
with ElasticSearchServer(config={
'logger.level': 'DEBUG',
# Keep index in memory
'index.store.type': 'mmapfs',
}) as es:
...
...or by setting them on the `config` attribute before starting the server:
.. code-block:: python
es = ElasticSearchServer()
es.config['logger.level'] = 'DEBUG'
es.start()
You can also setup a pytest fixture:
.. code-block:: python
@pytest.fixture(scope='session')
def elasticsearch(request):
"""
A testing fixture that provides a running elasticsearch server.
"""
es = ElasticSearchServer()
es.start()
request.addfinalizer(es.stop)
return es
Testing
-------
To run tests you'll need to install the test requirements::
pip install -r src/tests/requirements.txt
Run tests::
python src/tests/runtests.py