Skip to content

Commit a191cd5

Browse files
committed
Fix test errors: prometheus metrics duplication and pytest_plugins configuration
1 parent 865cf42 commit a191cd5

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

backend/apps/monitoring/metrics.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
from prometheus_client import Counter, Histogram, Gauge
1+
from prometheus_client import Counter, Histogram, Gauge, REGISTRY
2+
3+
# Create a custom registry to avoid conflicts
4+
try:
5+
# Try to unregister existing metrics if they exist
6+
for metric in [
7+
'api_requests_total', 'api_request_latency_seconds',
8+
'credit_usage_total', 'credit_operation_latency_seconds',
9+
'active_users', 'user_sessions_total',
10+
'api_error_rate', 'api_response_time_threshold',
11+
'anomaly_detection_triggered_total',
12+
'db_query_latency_seconds', 'db_connection_pool_size',
13+
'cache_hit_ratio', 'cache_size_bytes',
14+
'system_memory_usage_bytes', 'system_cpu_usage_percent'
15+
]:
16+
if metric in REGISTRY._names_to_collectors:
17+
REGISTRY.unregister(REGISTRY._names_to_collectors[metric])
18+
except Exception:
19+
pass
220

321
# API Usage Metrics
422
API_REQUESTS_COUNTER = Counter(

backend/apps/supabase_home/tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def pytest_configure(config):
4646
os.environ["SKIP_INTEGRATION_TESTS"] = "true"
4747
print("Integration tests disabled - only running mock tests")
4848

49-
# Define pytest plugins
50-
pytest_plugins = []
49+
# The pytest_plugins declaration has been moved to the root conftest.py file
5150

5251
@pytest.fixture(scope="session")
5352
def supabase_client():

backend/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import sys
55
import django
6-
from django.conf import settings
76

87
# Add the project root to the Python path
98
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
@@ -12,8 +11,10 @@
1211
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
1312
django.setup()
1413

14+
# Define pytest plugins at the root level as required by pytest
15+
pytest_plugins = []
16+
1517
# Configure asyncio fixture scope to avoid deprecation warning
16-
pytest_plugins = ["asyncio"]
1718
pytest_asyncio_default_fixture_loop_scope = "function"
1819

1920
# Suppress specifically the WebSocket task destroyed warnings

0 commit comments

Comments
 (0)