Skip to content

Commit f8e7592

Browse files
committed
fix pending issue with tests on mac
1 parent 9eab952 commit f8e7592

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ data/
1414
www/REFACTOR.md
1515
www/reload-frontend
1616
server/test.sqlite
17-
CLAUDE.local.md
17+
CLAUDE.local.md
18+
./www/.pnpm-store

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ uv run celery -A reflector.worker.app beat
4242
**Testing:**
4343
```bash
4444
# Run all tests with coverage
45-
uv run pytest
45+
REDIS_HOST=localhost CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/1 uv run pytest
4646

4747
# Run specific test file
48-
uv run pytest tests/test_transcripts.py
48+
REDIS_HOST=localhost CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/1 uv run pytest tests/test_transcripts.py
4949

5050
# Run tests with verbose output
51-
uv run pytest -v
51+
REDIS_HOST=localhost CELERY_BROKER_URL=redis://localhost:6379/1 CELERY_RESULT_BACKEND=redis://localhost:6379/1 uv run pytest -v
5252
```
5353

5454
**Process Audio Files:**

server/tests/conftest.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,69 @@
11
import os
2+
import subprocess
23
from tempfile import NamedTemporaryFile
34
from unittest.mock import patch
45

56
import pytest
67

78

8-
# Pytest-docker configuration
9+
# Pytest-docker configuration with cleanup
910
@pytest.fixture(scope="session")
1011
def docker_compose_file(pytestconfig):
1112
return os.path.join(str(pytestconfig.rootdir), "tests", "docker-compose.test.yml")
1213

1314

15+
@pytest.fixture(scope="session")
16+
def docker_compose_project_name():
17+
"""Use a consistent project name to avoid creating new networks each run."""
18+
return "reflector_test"
19+
20+
21+
@pytest.fixture(scope="session", autouse=True)
22+
def cleanup_docker_resources():
23+
"""Clean up Docker test resources before and after test session."""
24+
25+
def cleanup():
26+
# Stop and remove any existing test containers
27+
# This will also remove the reflector_test network if it exists
28+
subprocess.run(
29+
[
30+
"docker",
31+
"compose",
32+
"-p",
33+
"reflector_test",
34+
"down",
35+
"-v",
36+
"--remove-orphans",
37+
],
38+
capture_output=True,
39+
cwd=os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
40+
)
41+
# Clean up any unused networks (includes orphaned pytest networks)
42+
# This is safe - only removes networks with no attached containers
43+
subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
44+
45+
# Clean before tests
46+
cleanup()
47+
48+
yield
49+
50+
# Clean after tests
51+
cleanup()
52+
53+
1454
@pytest.fixture(scope="session")
1555
def postgres_service(docker_ip, docker_services):
1656
"""Ensure that PostgreSQL service is up and responsive."""
17-
port = docker_services.port_for("postgres_test", 5432)
57+
try:
58+
port = docker_services.port_for("postgres_test", 5432)
59+
except Exception as e:
60+
# If Docker services fail to start, clean up and retry
61+
subprocess.run(["docker", "network", "prune", "-f"], capture_output=True)
62+
subprocess.run(
63+
["docker", "compose", "-p", "reflector_test", "down", "-v"],
64+
capture_output=True,
65+
)
66+
raise pytest.skip(f"Docker services failed to start: {e}")
1867

1968
def is_responsive():
2069
try:

0 commit comments

Comments
 (0)