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
Open
fix: mock subprocess in test_missing_nvidia_smi_warning instead of relying on host hardware#73MLuqmanBR wants to merge 1 commit intoTheTom:mainfrom
MLuqmanBR wants to merge 1 commit intoTheTom:mainfrom
Conversation
…lying on host hardware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TestGracefulDegradation::test_missing_nvidia_smi_warningfails on anymachine that has
nvidia-smiinstalled (e.g. Linux with an NVIDIA GPU),because it calls
_nvidia_querywith no mock and asserts the result is"N/A". The stale inline comment reveals the assumption baked in:This violates the module's own stated contract — the file docstring reads:
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_failuses@patch("subprocess.check_output", side_effect=FileNotFoundError)tosimulate a missing binary.
test_missing_nvidia_smi_warningis the sametest without the mock.
Fix
Add the same
@patchdecorator that the rest of the test suite uses for_nvidia_query, and add amock_subpparameter to receive it. Removethe now-incorrect inline comment.
Changes
tests/test_turbo_hardware_diag.py—TestGracefulDegradation:Testing
nvidia-smireturnsreal temperature data).
FileNotFoundErrorpath that_nvidia_queryalready handles for graceful degradation, matchingthe behaviour of the existing
test_graceful_na_when_probes_failtest.Notes
No new dependencies. The
@patchdecorator andFileNotFoundErrorside-effect pattern are already used extensively in this file.