Skip to content

Commit 02448a7

Browse files
committed
fix elastic
1 parent b2a50bf commit 02448a7

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/pytest_databases/_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def run(
135135
transient: bool = False,
136136
ulimits: list[Ulimit] | None = None,
137137
shm_size: int | None = None,
138+
mem_limit: str | None = None,
138139
) -> Generator[ServiceContainer, None, None]:
139140
if check is None and wait_for_log is None:
140141
msg = "Must set at least check or wait_for_log"
@@ -161,6 +162,7 @@ def run(
161162
name=name,
162163
environment=env,
163164
ulimits=ulimits,
165+
mem_limit=mem_limit,
164166
)
165167
container.reload()
166168

src/pytest_databases/docker/elastic_search.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ def elasticsearch8_responsive(scheme: str, host: str, port: int, user: str, pass
4444
return False
4545

4646

47+
@pytest.fixture(scope="session")
48+
def elasticsearch_service_memory_limit() -> str:
49+
return "1g"
50+
51+
4752
@contextlib.contextmanager
4853
def _provide_elasticsearch_service(
4954
docker_service: DockerService,
5055
image: str,
5156
name: str,
5257
client_cls: type[Elasticsearch7 | Elasticsearch8],
58+
memory_limit: str,
5359
) -> Generator[ElasticsearchService, None, None]:
5460
user = "elastic"
5561
password = "changeme"
@@ -79,6 +85,7 @@ def check(_service: ServiceContainer) -> bool:
7985
timeout=120,
8086
pause=1,
8187
transient=True,
88+
mem_limit="1g",
8289
) as service:
8390
yield ElasticsearchService(
8491
host=service.host,
@@ -91,23 +98,31 @@ def check(_service: ServiceContainer) -> bool:
9198

9299

93100
@pytest.fixture(autouse=False, scope="session")
94-
def elasticsearch_7_service(docker_service: DockerService) -> Generator[ElasticsearchService, None, None]:
101+
def elasticsearch_7_service(
102+
docker_service: DockerService,
103+
elasticsearch_service_memory_limit: str,
104+
) -> Generator[ElasticsearchService, None, None]:
95105
with _provide_elasticsearch_service(
96106
docker_service=docker_service,
97107
image="elasticsearch:7.17.19",
98108
name="elasticsearch-7",
99109
client_cls=Elasticsearch7,
110+
memory_limit=elasticsearch_service_memory_limit,
100111
) as service:
101112
yield service
102113

103114

104115
@pytest.fixture(autouse=False, scope="session")
105-
def elasticsearch_8_service(docker_service: DockerService) -> Generator[ElasticsearchService, None, None]:
116+
def elasticsearch_8_service(
117+
docker_service: DockerService,
118+
elasticsearch_service_memory_limit: str,
119+
) -> Generator[ElasticsearchService, None, None]:
106120
with _provide_elasticsearch_service(
107121
docker_service=docker_service,
108122
image="elasticsearch:8.13.0",
109123
name="elasticsearch-8",
110124
client_cls=Elasticsearch8,
125+
memory_limit=elasticsearch_service_memory_limit,
111126
) as service:
112127
yield service
113128

tests/test_elasticsearch.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
def test_elasticsearch_7(pytester: pytest.Pytester) -> None:
1010
pytester.makepyfile("""
11+
from elasticsearch7 import Elasticsearch
12+
1113
pytest_plugins = ["pytest_databases.docker.elastic_search"]
1214
1315
def test(elasticsearch_7_service) -> None:
14-
with Elasticsearch7(
16+
with Elasticsearch(
1517
hosts=[
1618
{
1719
"host": elasticsearch_7_service.host,
@@ -33,10 +35,12 @@ def test(elasticsearch_7_service) -> None:
3335

3436
def test_elasticsearch_8(pytester: pytest.Pytester) -> None:
3537
pytester.makepyfile("""
38+
from elasticsearch7 import Elasticsearch
39+
3640
pytest_plugins = ["pytest_databases.docker.elastic_search"]
3741
3842
def test(elasticsearch_8_service) -> None:
39-
with Elasticsearch8(
43+
with Elasticsearch(
4044
hosts=[
4145
{
4246
"host": elasticsearch_8_service.host,

0 commit comments

Comments
 (0)