Automatically sets up an elasticsearch instance in a temporary directory, and destroys it after testing
Project description
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<https://bitbucket.org/tk0miya/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.dsn())
# perform any testing with elasticsearch here
# elasticsearch server is terminated and cleaned up here
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:
.. code-block:: python
pip install -r src/tests/requirements.txt
Run tests:
.. code-block:: python
python src/tests/runtests.py
=====================
`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<https://bitbucket.org/tk0miya/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.dsn())
# perform any testing with elasticsearch here
# elasticsearch server is terminated and cleaned up here
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:
.. code-block:: python
pip install -r src/tests/requirements.txt
Run tests:
.. code-block:: python
python src/tests/runtests.py
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
Close
Hashes for testing.elasticsearch-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b5b843363b3b9fccfcff30cff77571a77310bb3390d82f90b79bc068529e56b |
|
MD5 | 22618d808091b3232d7c1750abfd69ad |
|
BLAKE2b-256 | 2dae22c4da5524291d2158f76455bdc6ed6a178a132600285170f08f04f0c7e0 |