-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
I see that the mock client uses the random package to generate new IDs for documents (specifically random.choice).
In my project, I am generating an ES document after each test is ran, and resetting the random package's seed before each test is ran (this part is out of my control). Since the mock client is using the random package to generate IDs, then this means it generates the same ID for every test, which is not ideal for testing my document posting. I wonder if there is a way around this?
Repro (test_repro.py):
import elasticmock
import elasticsearch
import pytest
import random
@pytest.fixture
@elasticmock.elasticmock
def client(scope='session'):
c = elasticsearch.Elasticsearch()
c.indices.create('test')
return c
@pytest.fixture(autouse=True)
def setup_and_teardown(client):
random.seed(1)
yield
print(client.index(index='test', body={'test': 'test'})['_id'])
def test_1():
random.choice('abcde')
assert 1 == 1
def test_2():
random.choice('12345')
assert 1 == 1
Run with
python3 -m pip install pytest elasticmock elasticsearch
python3 -m pytest test_repro.py
Observe:
test_repro.py .K2ZWeqhFWCEPyYngFb51
.K2ZWeqhFWCEPyYngFb51
Metadata
Metadata
Assignees
Labels
No labels