Skip to content

Commit aecbf81

Browse files
committed
new mock rabbitmq for tests
1 parent 983c5cb commit aecbf81

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

backend/app/tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
from app.main import app
66
from app.tests.utils import delete_test_data, user_example
77
from fastapi.testclient import TestClient
8+
from unittest.mock import AsyncMock, patch
9+
10+
11+
@pytest.fixture(autouse=True)
12+
def mock_rabbitmq():
13+
"""Mock RabbitMQ connections for all tests"""
14+
with patch('aio_pika.connect_robust') as mock_connect:
15+
mock_channel = AsyncMock()
16+
mock_exchange = AsyncMock()
17+
mock_connection = AsyncMock()
18+
19+
mock_connect.return_value = mock_connection
20+
mock_connection.__aenter__.return_value = mock_connection
21+
mock_connection.channel.return_value = mock_channel
22+
mock_channel.declare_exchange.return_value = mock_exchange
23+
24+
yield mock_connect
825

926
settings.MONGO_DATABASE = "clowder-tests"
1027
settings.elasticsearch_index = "clowder-tests"

0 commit comments

Comments
 (0)