Skip to content

Commit d9ad5d0

Browse files
committed
fix(tests): resolve linting issues in fitness test reorganization
- Remove unused imports from test files (fixtures now provided by conftest.py) - Fix line length violations by breaking long lines appropriately - Improve test readability by extracting long string literals into variables
1 parent 5eb2ddd commit d9ad5d0

4 files changed

Lines changed: 29 additions & 23 deletions

File tree

tests/test_serverless/test_modules/test_fitness/test_gpu_checks.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_check_gpu_health,
2020
auto_register_gpu_check,
2121
)
22-
from runpod.serverless.modules.rp_fitness import clear_fitness_checks, _fitness_checks
22+
from runpod.serverless.modules.rp_fitness import _fitness_checks
2323

2424

2525
# ============================================================================
@@ -146,7 +146,8 @@ def test_finds_package_binary(self):
146146

147147
def test_returns_none_if_binary_not_found(self):
148148
"""Test returns None when binary not in package."""
149-
with patch("runpod.serverless.modules.rp_gpu_fitness.get_binary_path") as mock_get:
149+
patch_path = "runpod.serverless.modules.rp_gpu_fitness.get_binary_path"
150+
with patch(patch_path) as mock_get:
150151
mock_get.return_value = None
151152
path = _get_gpu_test_binary_path()
152153
assert path is None
@@ -331,8 +332,8 @@ def test_auto_register_nvidia_smi_failed(self):
331332

332333
def test_auto_register_timeout(self):
333334
"""Test auto-registration handles timeout."""
334-
with patch("subprocess.run", side_effect=subprocess.TimeoutExpired("nvidia-smi", 5)):
335-
335+
timeout_error = subprocess.TimeoutExpired("nvidia-smi", 5)
336+
with patch("subprocess.run", side_effect=timeout_error):
336337
auto_register_gpu_check()
337338

338339
# Should handle gracefully and not register

tests/test_serverless/test_modules/test_fitness/test_gpu_integration.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from runpod.serverless.modules.rp_fitness import (
1515
register_fitness_check,
1616
run_fitness_checks,
17-
clear_fitness_checks,
18-
_reset_registration_state,
1917
)
2018
from runpod.serverless.modules.rp_gpu_fitness import _check_gpu_health
2119

@@ -50,7 +48,9 @@ def mock_gpu_test_binary():
5048
@pytest.fixture
5149
def mock_gpu_test_binary_failure():
5250
"""Create a temporary mock gpu_test binary that outputs failure."""
53-
with tempfile.NamedTemporaryFile(mode="w", suffix="_gpu_test_fail", delete=False) as f:
51+
with tempfile.NamedTemporaryFile(
52+
mode="w", suffix="_gpu_test_fail", delete=False
53+
) as f:
5454
f.write("""#!/bin/bash
5555
cat <<'EOF'
5656
Failed to initialize NVML: Driver/library version mismatch
@@ -73,7 +73,9 @@ def mock_gpu_test_binary_failure():
7373
@pytest.fixture
7474
def mock_gpu_test_binary_multi_gpu():
7575
"""Create a temporary mock gpu_test binary with multiple GPUs."""
76-
with tempfile.NamedTemporaryFile(mode="w", suffix="_gpu_test_multi", delete=False) as f:
76+
with tempfile.NamedTemporaryFile(
77+
mode="w", suffix="_gpu_test_multi", delete=False
78+
) as f:
7779
f.write("""#!/bin/bash
7880
cat <<'EOF'
7981
Linux Kernel Version: 5.15.0
@@ -121,7 +123,9 @@ async def gpu_check():
121123
await run_fitness_checks()
122124

123125
@pytest.mark.asyncio
124-
async def test_fitness_check_with_failure_binary(self, mock_gpu_test_binary_failure):
126+
async def test_fitness_check_with_failure_binary(
127+
self, mock_gpu_test_binary_failure
128+
):
125129
"""Test fitness check fails with broken binary output."""
126130
@register_fitness_check
127131
async def gpu_check():

tests/test_serverless/test_modules/test_fitness/test_registration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ def failing_check():
353353

354354
# Should log error with check name and exception type
355355
error_calls = [str(call) for call in mock_log.error.call_args_list]
356-
assert any("failing_check" in call and "RuntimeError" in call for call in error_calls)
356+
has_error = any(
357+
"failing_check" in call and "RuntimeError" in call for call in error_calls
358+
)
359+
assert has_error
357360

358361
@pytest.mark.asyncio
359362
@patch("runpod.serverless.modules.rp_fitness.log")

tests/test_serverless/test_modules/test_fitness/test_system_checks.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_parse_version,
2323
auto_register_system_checks,
2424
)
25-
from runpod.serverless.modules.rp_fitness import clear_fitness_checks, _fitness_checks
25+
from runpod.serverless.modules.rp_fitness import _fitness_checks
2626

2727

2828
# ============================================================================
@@ -230,16 +230,14 @@ async def test_get_cuda_version_nvcc(self, mock_run):
230230
async def test_get_cuda_version_nvidia_smi_fallback(self, mock_run):
231231
"""Test CUDA version retrieval fallback to nvidia-smi."""
232232
# First call (nvcc) fails, second call (nvidia-smi) succeeds
233+
nvidia_smi_output = (
234+
"\n+-----------------------------------------------------------------------+\n"
235+
"| NVIDIA-SMI 565.57 Driver Version: 565.57 CUDA Version: 12.7 |\n"
236+
"+-----------------------------------------------------------------------+\n"
237+
)
233238
mock_run.side_effect = [
234239
FileNotFoundError(), # nvcc not found
235-
MagicMock(
236-
returncode=0,
237-
stdout="""
238-
+-----------------------------------------------------------------------------------------+
239-
| NVIDIA-SMI 565.57 Driver Version: 565.57 CUDA Version: 12.7 |
240-
|--------------------------------------+------------------------+------------------------+
241-
"""
242-
),
240+
MagicMock(returncode=0, stdout=nvidia_smi_output),
243241
]
244242
version = await _get_cuda_version()
245243
assert version is not None
@@ -261,12 +259,12 @@ async def test_get_cuda_version_nvidia_smi_no_cuda_in_output(self, mock_run):
261259
@patch("subprocess.run")
262260
async def test_get_cuda_version_extraction_from_nvidia_smi(self, mock_run):
263261
"""Test that CUDA version is correctly extracted from nvidia-smi."""
262+
smi_output = (
263+
"NVIDIA-SMI 565.57 Driver Version: 565.57 CUDA Version: 12.2"
264+
)
264265
mock_run.side_effect = [
265266
FileNotFoundError(), # nvcc not found
266-
MagicMock(
267-
returncode=0,
268-
stdout="NVIDIA-SMI 565.57 Driver Version: 565.57 CUDA Version: 12.2"
269-
),
267+
MagicMock(returncode=0, stdout=smi_output),
270268
]
271269
version = await _get_cuda_version()
272270
assert version is not None

0 commit comments

Comments
 (0)