Automatically sets up an elasticsearch instance in a temporary directory, and destroys it after testing
Project description
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:
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:
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:
es = ElasticSearchServer()
es.config['logger.level'] = 'DEBUG'
es.start()
You can also setup a pytest fixture:
@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
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
Built Distribution
Hashes for testing.elasticsearch-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7a9065403ee07ec6d22f311369697bbc41141fffc218bf95b24e0c93b6a44f7 |
|
MD5 | a3fe22981bed588836d66a3d3646c533 |
|
BLAKE2b-256 | 1f3015cec34c92f602a05d1aab6a4b8c4b4a09521f7f1e14d21dd527cbdaa207 |
Hashes for testing.elasticsearch-0.3.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db09fb9bcaec3a090abf025b7b2813b24839c35736c823324f249f09aaf6f682 |
|
MD5 | 74643e66f74e3e5d35e7a38bc33e17b3 |
|
BLAKE2b-256 | 3862c65f6dca45f1ee47db691b4ff74906181c47d885f82bc7e4b3d580a188c7 |