Skip to content

fix: mock subprocess in test_missing_nvidia_smi_warning instead of relying on host hardware#73

Open
MLuqmanBR wants to merge 1 commit intoTheTom:mainfrom
MLuqmanBR:fix-test-nvidia-smi
Open

fix: mock subprocess in test_missing_nvidia_smi_warning instead of relying on host hardware#73
MLuqmanBR wants to merge 1 commit intoTheTom:mainfrom
MLuqmanBR:fix-test-nvidia-smi

Conversation

@MLuqmanBR
Copy link
Copy Markdown

Problem

TestGracefulDegradation::test_missing_nvidia_smi_warning fails on any
machine that has nvidia-smi installed (e.g. Linux with an NVIDIA GPU),
because it calls _nvidia_query with no mock and asserts the result is
"N/A". The stale inline comment reveals the assumption baked in:

# On macOS (where these tests actually run), nvidia-smi doesn't exist
assert result == "N/A"

This violates the module's own stated contract — the file docstring reads:

"100% line coverage target with NO real subprocess calls, GPU, or
llama.cpp binaries. All platform-specific probes are mocked.
Tests pass on macOS AND Linux."

The test makes a real subprocess call, depends on host hardware, and
only passes on macOS. It fails on Linux with an NVIDIA GPU even when
the installation is correct.

Root Cause

A duplicate of this test already exists and is implemented correctly:
TestBackgroundMonitor::test_graceful_na_when_probes_fail uses
@patch("subprocess.check_output", side_effect=FileNotFoundError) to
simulate a missing binary. test_missing_nvidia_smi_warning is the same
test without the mock.

Fix

Add the same @patch decorator that the rest of the test suite uses for
_nvidia_query, and add a mock_subp parameter to receive it. Remove
the now-incorrect inline comment.

Changes

tests/test_turbo_hardware_diag.pyTestGracefulDegradation:

# Before
def test_missing_nvidia_smi_warning(self, tmp_path):
    result = thd.BackgroundMonitor._nvidia_query("temperature.gpu")
    # On macOS (where these tests actually run), nvidia-smi doesn't exist
    assert result == "N/A"

# After
@patch("subprocess.check_output", side_effect=FileNotFoundError)
def test_missing_nvidia_smi_warning(self, mock_subp, tmp_path):
    result = thd.BackgroundMonitor._nvidia_query("temperature.gpu")
    assert result == "N/A"

Testing

  • 557/557 pass on Linux with an NVIDIA GPU present (nvidia-smi returns
    real temperature data).
  • The mock correctly triggers the FileNotFoundError path that
    _nvidia_query already handles for graceful degradation, matching
    the behaviour of the existing test_graceful_na_when_probes_fail test.

Notes

No new dependencies. The @patch decorator and FileNotFoundError
side-effect pattern are already used extensively in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant