Skip to content

Commit 5eb2ddd

Browse files
committed
refactor(tests): reorganize fitness check tests into dedicated subdirectory
Consolidate fragmented fitness check tests (test_fitness.py, test_system_fitness.py, test_gpu_fitness.py, test_gpu_fitness_integration.py) into organized structure: - test_fitness/conftest.py: Shared fixtures for all fitness tests - test_fitness/test_registration.py: Fitness check framework tests - test_fitness/test_system_checks.py: System resource check tests - test_fitness/test_gpu_checks.py: GPU-specific check tests - test_fitness/test_gpu_integration.py: GPU integration tests This improves code organization and eliminates duplicate fixture definitions.
1 parent 26c845a commit 5eb2ddd

6 files changed

Lines changed: 25 additions & 48 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Fitness check system tests."""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Shared fixtures for fitness check tests."""
2+
3+
import pytest
4+
5+
from runpod.serverless.modules.rp_fitness import (
6+
clear_fitness_checks,
7+
_reset_registration_state,
8+
)
9+
10+
11+
@pytest.fixture(autouse=True)
12+
def cleanup_fitness_checks(monkeypatch):
13+
"""Automatically clean up fitness checks before and after each test.
14+
15+
Disables auto-registration of system checks to avoid interference
16+
with fitness check framework tests.
17+
"""
18+
monkeypatch.setenv("RUNPOD_SKIP_AUTO_SYSTEM_CHECKS", "true")
19+
_reset_registration_state()
20+
clear_fitness_checks()
21+
yield
22+
_reset_registration_state()
23+
clear_fitness_checks()

tests/test_serverless/test_modules/test_gpu_fitness.py renamed to tests/test_serverless/test_modules/test_fitness/test_gpu_checks.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
from runpod.serverless.modules.rp_fitness import clear_fitness_checks, _fitness_checks
2323

2424

25-
@pytest.fixture(autouse=True)
26-
def cleanup_fitness_checks():
27-
"""Automatically clean up fitness checks before and after each test."""
28-
clear_fitness_checks()
29-
yield
30-
clear_fitness_checks()
31-
32-
3325
# ============================================================================
3426
# Output Parsing Tests
3527
# ============================================================================

tests/test_serverless/test_modules/test_gpu_fitness_integration.py renamed to tests/test_serverless/test_modules/test_fitness/test_gpu_integration.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020
from runpod.serverless.modules.rp_gpu_fitness import _check_gpu_health
2121

2222

23-
@pytest.fixture(autouse=True)
24-
def cleanup_checks(monkeypatch):
25-
"""Clean fitness checks before and after each test."""
26-
# Disable auto-registration of system checks for GPU fitness integration tests
27-
monkeypatch.setenv("RUNPOD_SKIP_AUTO_SYSTEM_CHECKS", "true")
28-
_reset_registration_state()
29-
clear_fitness_checks()
30-
yield
31-
_reset_registration_state()
32-
clear_fitness_checks()
33-
34-
3523
@pytest.fixture
3624
def mock_gpu_test_binary():
3725
"""Create a temporary mock gpu_test binary that outputs success."""

tests/test_serverless/test_modules/test_fitness.py renamed to tests/test_serverless/test_modules/test_fitness/test_registration.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Tests for the fitness check system (rp_fitness module).
1+
"""Tests for the fitness check system (rp_fitness module).
32
43
Fitness checks are used to validate worker health at startup before handler
54
initialization. Only tests registration, execution, and error handling of
@@ -14,22 +13,9 @@
1413
run_fitness_checks,
1514
clear_fitness_checks,
1615
_fitness_checks,
17-
_reset_registration_state,
1816
)
1917

2018

21-
@pytest.fixture(autouse=True)
22-
def cleanup_fitness_checks(monkeypatch):
23-
"""Automatically clean up fitness checks before and after each test."""
24-
# Disable auto-registration of system checks for isolated fitness check tests
25-
monkeypatch.setenv("RUNPOD_SKIP_AUTO_SYSTEM_CHECKS", "true")
26-
_reset_registration_state()
27-
clear_fitness_checks()
28-
yield
29-
_reset_registration_state()
30-
clear_fitness_checks()
31-
32-
3319
# ============================================================================
3420
# Registration Tests
3521
# ============================================================================
@@ -116,7 +102,6 @@ def check():
116102
class TestFitnessExecutionSuccess:
117103
"""Tests for successful fitness check execution."""
118104

119-
120105
@pytest.mark.asyncio
121106
async def test_empty_registry_no_op(self):
122107
"""Test that empty registry results in no-op."""
@@ -205,7 +190,6 @@ async def async_check():
205190
class TestFitnessExecutionFailure:
206191
"""Tests for fitness check execution failures."""
207192

208-
209193
@pytest.mark.asyncio
210194
async def test_sync_check_fails(self):
211195
"""Test that synchronous check failure causes exit."""
@@ -306,7 +290,6 @@ def check():
306290
class TestFitnessLogging:
307291
"""Tests for fitness check logging behavior."""
308292

309-
310293
@pytest.mark.asyncio
311294
@patch("runpod.serverless.modules.rp_fitness.log")
312295
async def test_logs_debug_when_no_checks(self, mock_log):
@@ -395,7 +378,6 @@ def check():
395378
class TestFitnessClearRegistry:
396379
"""Tests for fitness check registry cleanup."""
397380

398-
399381
def test_clear_fitness_checks(self):
400382
"""Test that clear_fitness_checks empties the registry."""
401383
@register_fitness_check
@@ -428,7 +410,6 @@ def check():
428410
class TestFitnessIntegration:
429411
"""Integration tests for fitness check system."""
430412

431-
432413
@pytest.mark.asyncio
433414
async def test_check_with_real_exception_message(self):
434415
"""Test that real exception messages are preserved."""

tests/test_serverless/test_modules/test_system_fitness.py renamed to tests/test_serverless/test_modules/test_fitness/test_system_checks.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525
from runpod.serverless.modules.rp_fitness import clear_fitness_checks, _fitness_checks
2626

2727

28-
@pytest.fixture(autouse=True)
29-
def cleanup_fitness_checks():
30-
"""Automatically clean up fitness checks before and after each test."""
31-
clear_fitness_checks()
32-
yield
33-
clear_fitness_checks()
34-
35-
3628
# ============================================================================
3729
# Memory Check Tests
3830
# ============================================================================

0 commit comments

Comments
 (0)