rteval: Improve test_stressng output readability
PATCH 1/1 rteval: Improve test_stressng output readability
Rewrite the test docstrings in the concise "Test when ..." style used by test_measurement_module_selection.py, and run the suite with verbosity=2 through a main() wrapper so each test prints its description as it runs.
The tests exercise the stress-ng error paths, which emit messages to stderr. Without descriptions these messages appeared on their own and looked alarming. Now each one is preceded by a clear statement of the test that produces it, making the expected error output easy to follow.
Assisted-by Claude:claude-opus-4-8
Signed-off-by John Kacur <[email protected]>
--- tests/test_stressng.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tests/test_stressng.py +10 -6
@@ -15,14 +15,14 @@ class TestGetValidStressors(unittest.TestCase): @patch('rteval.modules.loads.stressng.subprocess.run') def test_parses_stressor_list(self, mock_run): - """Tests that the function works for multiple correct inputs""" + """Test parsing a valid stress-ng stressor list""" mock_run.return_value = MagicMock(stdout="cpu vm matrix\n") self.assertEqual(stressng.get_valid_stressors(), ['cpu', 'vm', 'matrix']) @patch('rteval.modules.loads.stressng.subprocess.run', side_effect=FileNotFoundError) def test_not_installed_exits(self, _): - """Tests that the program exits correctly if stress-ng is not installed""" + """Test when stress-ng is not installed""" with self.assertRaises(SystemExit) as cm: stressng.get_valid_stressors() self.assertEqual(cm.exception.code, 1)
@@ -30,7 +30,7 @@ class TestGetValidStressors(unittest.TestCase): @patch('rteval.modules.loads.stressng.subprocess.run', side_effect=subprocess.CalledProcessError(1, 'stress-ng')) def test_query_failure_exits(self, _): - """Tests that the program exits correctly if the query attempt fails""" + """Test when the stress-ng query fails""" with self.assertRaises(SystemExit): stressng.get_valid_stressors()
@@ -40,16 +40,20 @@ class TestValidateStressor(unittest.TestCase): @patch('rteval.modules.loads.stressng.get_valid_stressors', return_value=['cpu', 'vm']) def test_valid_passes(self, _): - """Tests that the function works for correct inputs""" + """Test that a valid stressor is accepted""" stressng.validate_stressor('cpu') # should not raise @patch('rteval.modules.loads.stressng.get_valid_stressors', return_value=['cpu', 'vm']) def test_invalid_exits(self, _): - """Tests that the function exits properly for incorrect inputs""" + """Test that an invalid stressor is rejected""" with self.assertRaises(SystemExit) as cm: stressng.validate_stressor('bogus') self.assertEqual(cm.exception.code, 1) +def main(): + """Run the test suite""" + unittest.main(verbosity=2) + if __name__ == '__main__': - unittest.main() + main()
Signature · 1 line
2.55.0