Coverage for tests/conftest.py: 97%
25 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:14 -0600
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:14 -0600
1"""Top-level conftest.py"""
2from os import environ
3import random
4import string
5import pytest
6from es_client import Builder
7from es_client.helpers.logging import set_logging
9LOGLEVEL = 'DEBUG'
11@pytest.fixture(scope="session")
12def client():
13 """Return an Elasticsearch client"""
14 host = environ.get('TEST_ES_SERVER', 'http://127.0.0.1:9200')
15 set_logging({'loglevel': LOGLEVEL, 'blacklist': ['elastic_transport', 'urllib3']})
16 builder = Builder(configdict={'elasticsearch': {'client': {'hosts': host}}})
17 builder.connect()
18 return builder.client
20@pytest.fixture(scope="module")
21def prefix():
22 """Return a random prefix"""
23 return randomstr(length=8, lowercase=True)
25@pytest.fixture(scope="module")
26def uniq():
27 """Return a random uniq value"""
28 return randomstr(length=8, lowercase=True)
30def randomstr(length: int=16, lowercase: bool=False):
31 """Generate a random string"""
32 letters = string.ascii_uppercase
33 if lowercase: 33 ↛ 35line 33 didn't jump to line 35, because the condition on line 33 was never false
34 letters = string.ascii_lowercase
35 return str(''.join(random.choices(letters + string.digits, k=length)))