Skip to content

Commit 36db52e

Browse files
authored
Replace docker-compose by testcontainers (#343)
1 parent aec8e1f commit 36db52e

File tree

7 files changed

+18
-36
lines changed

7 files changed

+18
-36
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ jobs:
6363
echo "203.0.113.0 logfire.dev" | sudo tee -a /etc/hosts
6464
echo "203.0.113.0 logfire-api.pydantic.dev" | sudo tee -a /etc/hosts
6565
echo "203.0.113.0 logfire.pydantic.dev" | sudo tee -a /etc/hosts
66-
- name: Setup services
67-
run: docker-compose up -d
6866
- name: set up python
6967
uses: actions/setup-python@v5
7068
with:

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ lint:
3030
test:
3131
rye run coverage run -m pytest
3232

33-
.PHONY: test-integration # Run the integration tests
34-
test-integration:
35-
rye run coverage run -m pytest -m 'integration'
36-
3733
.PHONY: generate-stubs # Generate stubs for logfire-api
3834
generate-stubs:
3935
rye run generate-stubs

compose.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ dev-dependencies = [
135135
"sqlmodel",
136136
"mypy>=1.10.0",
137137
"celery>=5.4.0",
138+
"testcontainers",
138139
]
139140

140141
[tool.rye.scripts]
@@ -213,7 +214,6 @@ venvPath = ".venv"
213214

214215
[tool.pytest.ini_options]
215216
xfail_strict = true
216-
markers = ['integration: mark a test as an integration test']
217217
filterwarnings = [
218218
"error",
219219
# fastapi uses deprecated pydantic functions

requirements-dev.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# features: []
77
# all-features: false
88
# with-sources: false
9-
# generate-hashes: false
109

1110
-e file:.
1211
aiohttp==3.9.5
@@ -85,6 +84,8 @@ django==5.0.7
8584
dnspython==2.6.1
8685
# via email-validator
8786
# via pymongo
87+
docker==7.1.0
88+
# via testcontainers
8889
email-validator==2.2.0
8990
# via fastapi
9091
eval-type-backport==0.2.0
@@ -378,6 +379,7 @@ redis==5.0.7
378379
regex==2024.7.24
379380
# via mkdocs-material
380381
requests==2.32.3
382+
# via docker
381383
# via huggingface-hub
382384
# via mkdocs-material
383385
# via opentelemetry-exporter-otlp-proto-http
@@ -409,6 +411,7 @@ sqlparse==0.5.1
409411
starlette==0.37.2
410412
# via fastapi
411413
structlog==24.4.0
414+
testcontainers==4.7.2
412415
tokenizers==0.19.1
413416
# via anthropic
414417
toml==0.10.2
@@ -433,12 +436,15 @@ typing-extensions==4.12.2
433436
# via pydantic
434437
# via pydantic-core
435438
# via sqlalchemy
439+
# via testcontainers
436440
# via typer
437441
tzdata==2024.1
438442
# via celery
439443
# via pandas
440444
urllib3==2.2.2
445+
# via docker
441446
# via requests
447+
# via testcontainers
442448
uvicorn==0.30.3
443449
# via fastapi
444450
uvloop==0.19.0
@@ -466,6 +472,7 @@ wrapt==1.16.0
466472
# via opentelemetry-instrumentation-dbapi
467473
# via opentelemetry-instrumentation-redis
468474
# via opentelemetry-instrumentation-sqlalchemy
475+
# via testcontainers
469476
yarl==1.9.4
470477
# via aiohttp
471478
zipp==3.19.2

requirements.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# features: []
77
# all-features: false
88
# with-sources: false
9-
# generate-hashes: false
109

1110
-e file:.
1211
certifi==2024.7.4

tests/otel_integrations/test_celery.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
1-
"""This module contains tests for the Celery integration.
2-
3-
To be able to run those tests, you need to have Redis running on localhost:6379.
4-
We have a docker compose file that you can use to start Redis:
5-
6-
```bash
7-
docker compose up -d redis
8-
```
9-
"""
10-
111
import logging
12-
from typing import Iterator
2+
from typing import Generator, Iterator
133

144
import pytest
15-
import redis
16-
import redis.exceptions
175
from celery import Celery
186
from celery.contrib.testing.worker import start_worker
197
from celery.worker.worker import WorkController
208
from dirty_equals import IsStr
219
from inline_snapshot import snapshot
2210
from opentelemetry.instrumentation.celery import CeleryInstrumentor
11+
from testcontainers.redis import RedisContainer
2312

2413
import logfire
2514
from logfire.testing import TestExporter
2615

27-
pytestmark = [pytest.mark.integration]
2816

29-
try:
30-
client = redis.Redis()
31-
client.ping() # type: ignore
32-
except redis.exceptions.ConnectionError: # pragma: no cover
33-
pytestmark.append(pytest.mark.skip('Redis is not running'))
17+
@pytest.fixture(scope='module', autouse=True)
18+
def redis_container() -> Generator[RedisContainer, None, None]:
19+
with RedisContainer('redis:latest') as redis:
20+
yield redis
3421

3522

3623
@pytest.fixture
37-
def celery_app() -> Iterator[Celery]:
38-
app = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')
24+
def celery_app(redis_container: RedisContainer) -> Iterator[Celery]:
25+
redis_uri = f'redis://{redis_container.get_container_host_ip()}:{redis_container.get_exposed_port(6379)}/0'
26+
app = Celery('tasks', broker=redis_uri, backend=redis_uri)
3927

4028
@app.task(name='tasks.say_hello') # type: ignore
4129
def say_hello(): # type: ignore

0 commit comments

Comments
 (0)