@@ -225,11 +225,10 @@ def test_bmc_summary_regular_output(self):
225225 mock_bmc .get_eeprom .return_value = self .TEST_BMC_EEPROM_INFO
226226 mock_bmc .get_version .return_value = self .TEST_BMC_VERSION
227227
228- sys .modules ['sonic_platform' ].platform .Platform .return_value = mock_platform
229-
230- result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['summary' ], [])
231- assert result .exit_code == 0 , result .output
232- assert result .output == textwrap .dedent (expected_output )
228+ with mock .patch ('sonic_platform.platform.Platform' , return_value = mock_platform ):
229+ result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['summary' ], [])
230+ assert result .exit_code == 0 , result .output
231+ assert result .output == textwrap .dedent (expected_output )
233232
234233 def test_bmc_summary_json_output (self ):
235234 """Test 'show platform bmc summary' with JSON output"""
@@ -251,12 +250,11 @@ def test_bmc_summary_json_output(self):
251250 mock_bmc .get_eeprom .return_value = self .TEST_BMC_EEPROM_INFO
252251 mock_bmc .get_version .return_value = self .TEST_BMC_VERSION
253252
254- sys .modules ['sonic_platform' ].platform .Platform .return_value = mock_platform
255-
256- result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['summary' ], ['--json' ])
257- assert result .exit_code == 0 , result .output
258- output_json = json .loads (result .output )
259- assert output_json == expected_json
253+ with mock .patch ('sonic_platform.platform.Platform' , return_value = mock_platform ):
254+ result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['summary' ], ['--json' ])
255+ assert result .exit_code == 0 , result .output
256+ output_json = json .loads (result .output )
257+ assert output_json == expected_json
260258
261259 def test_bmc_eeprom_regular_output (self ):
262260 """Test 'show platform bmc eeprom' with regular output"""
@@ -282,11 +280,10 @@ def test_bmc_eeprom_regular_output(self):
282280 mock_chassis .get_bmc .return_value = mock_bmc
283281 mock_bmc .get_eeprom .return_value = self .TEST_BMC_EEPROM_INFO
284282
285- sys .modules ['sonic_platform' ].platform .Platform .return_value = mock_platform
286-
287- result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['eeprom' ], [])
288- assert result .exit_code == 0 , result .output
289- assert result .output == textwrap .dedent (expected_output )
283+ with mock .patch ('sonic_platform.platform.Platform' , return_value = mock_platform ):
284+ result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['eeprom' ], [])
285+ assert result .exit_code == 0 , result .output
286+ assert result .output == textwrap .dedent (expected_output )
290287
291288 def test_bmc_eeprom_json_output (self ):
292289 """Test 'show platform bmc eeprom' with JSON output"""
@@ -306,9 +303,8 @@ def test_bmc_eeprom_json_output(self):
306303 mock_chassis .get_bmc .return_value = mock_bmc
307304 mock_bmc .get_eeprom .return_value = self .TEST_BMC_EEPROM_INFO
308305
309- sys .modules ['sonic_platform' ].platform .Platform .return_value = mock_platform
310-
311- result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['eeprom' ], ['--json' ])
312- assert result .exit_code == 0 , result .output
313- output_json = json .loads (result .output )
314- assert output_json == expected_json
306+ with mock .patch ('sonic_platform.platform.Platform' , return_value = mock_platform ):
307+ result = CliRunner ().invoke (show .cli .commands ['platform' ].commands ['bmc' ].commands ['eeprom' ], ['--json' ])
308+ assert result .exit_code == 0 , result .output
309+ output_json = json .loads (result .output )
310+ assert output_json == expected_json
0 commit comments