Skip to content

Commit e6993bb

Browse files
Fix warning messages due to nose test deprecation
Multiple warnings similar to the below are emitted during test execution: ``` tests/vnet_route_check_test.py::TestVnetRouteCheck::test_vnet_route_check /usr/lib/python3/dist-packages/_pytest/fixtures.py:901: PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release. tests/vnet_route_check_test.py::TestVnetRouteCheck::test_vnet_route_check is using nose-specific method: `setup(self)` To remove this warning, rename it to `setup_method(self)` See docs: https://docs.pytest.org/en/stable/deprecations.html#support-for-tests-written-for-nose ``` Rename `def setup(self)` to `def setup_method(self)` and `def teardown(self)` to `def teardown_method(self)` as per documentation. Signed-off-by: Brad House <bhouse@nexthop.ai>
1 parent 7660b19 commit e6993bb

12 files changed

+69
-69
lines changed

tests/clear_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from unittest.mock import patch, MagicMock
66

77
class TestClear(object):
8-
def setup(self):
8+
def setup_method(self):
99
print('SETUP')
1010

1111
@patch('clear.main.run_command')
@@ -115,12 +115,12 @@ def test_clear_switchcounters(self, run_command):
115115
assert result.exit_code == 0
116116
run_command.assert_called_with(['switchstat', '-c'])
117117

118-
def teardown(self):
118+
def teardown_method(self):
119119
print('TEAR DOWN')
120120

121121

122122
class TestClearQuaggav4(object):
123-
def setup(self):
123+
def setup_method(self):
124124
print('SETUP')
125125

126126
@patch('clear.main.run_command')
@@ -176,12 +176,12 @@ def test_clear_ipv4_quagga(self, run_command):
176176
assert result.exit_code == 0
177177
run_command.assert_called_with(['sudo', 'vtysh', '-c', "clear ip bgp 10.0.0.1 soft out"])
178178

179-
def teardown(self):
179+
def teardown_method(self):
180180
print('TEAR DOWN')
181181

182182

183183
class TestClearQuaggav6(object):
184-
def setup(self):
184+
def setup_method(self):
185185
print('SETUP')
186186

187187
@patch('clear.main.run_command')
@@ -237,12 +237,12 @@ def test_clear_ipv6_quagga(self, run_command):
237237
assert result.exit_code == 0
238238
run_command.assert_called_with(['sudo', 'vtysh', '-c', "clear ipv6 bgp 10.0.0.1 soft out"])
239239

240-
def teardown(self):
240+
def teardown_method(self):
241241
print('TEAR DOWN')
242242

243243

244244
class TestClearFrr(object):
245-
def setup(self):
245+
def setup_method(self):
246246
print('SETUP')
247247

248248
@patch('clear.main.run_command')
@@ -298,12 +298,12 @@ def test_clear_ipv6_frr(self, run_command):
298298
assert result.exit_code == 0
299299
run_command.assert_called_with(['sudo', 'vtysh', '-c', "clear bgp ipv6 10.0.0.1 soft out"])
300300

301-
def teardown(self):
301+
def teardown_method(self):
302302
print('TEAR DOWN')
303303

304304

305305
class TestClearFlowcnt(object):
306-
def setup(self):
306+
def setup_method(self):
307307
print('SETUP')
308308

309309
@patch('utilities_common.cli.run_command')
@@ -330,6 +330,6 @@ def test_flowcnt_route_route(self, mock_run_command):
330330
assert result.exit_code == 0
331331
mock_run_command.assert_called_with(['flow_counters_stat', '-c', '-t', 'route', '--prefix', '3.3.0.0/16', '--vrf', str('Vrf_1'), '-n', 'asic0'])
332332

333-
def teardown(self):
333+
def teardown_method(self):
334334
print('TEAR DOWN')
335335

tests/config_test.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def mock_run_command_side_effect_disabled_timer(*args, **kwargs):
402402
sonic_cfggen = load_module_from_source('sonic_cfggen', '/usr/local/bin/sonic-cfggen')
403403

404404
class TestHelper(object):
405-
def setup(self):
405+
def setup_method(self):
406406
print("SETUP")
407407

408408
@patch('config.main.subprocess.Popen')
@@ -417,11 +417,11 @@ def test_get_device_type(self, mock_subprocess):
417417
mock_subprocess.assert_called_with(['/usr/local/bin/sonic-cfggen', '-m', '-v', 'DEVICE_METADATA.localhost.type'], text=True, stdout=-1)
418418
assert device_type == "Unknown"
419419

420-
def teardown(self):
420+
def teardown_method(self):
421421
print("TEARDOWN")
422422

423423
class TestConfig(object):
424-
def setup(self):
424+
def setup_method(self):
425425
print("SETUP")
426426

427427
@patch('config.main.subprocess.check_call')
@@ -3463,7 +3463,7 @@ def teardown_class(cls):
34633463

34643464

34653465
class TestConfigPfcwd(object):
3466-
def setup(self):
3466+
def setup_method(self):
34673467
print("SETUP")
34683468

34693469
@patch('utilities_common.cli.run_command')
@@ -3520,12 +3520,12 @@ def test_start_default(self, mock_run_command):
35203520
assert result.exit_code == 0
35213521
mock_run_command.assert_called_once_with(['pfcwd', 'start_default'], display_cmd=True)
35223522

3523-
def teardown(self):
3523+
def teardown_method(self):
35243524
print("TEARDOWN")
35253525

35263526

35273527
class TestConfigAclUpdate(object):
3528-
def setup(self):
3528+
def setup_method(self):
35293529
print("SETUP")
35303530

35313531
@patch('utilities_common.cli.run_command')
@@ -3548,12 +3548,12 @@ def test_incremental(self, mock_run_command):
35483548
assert result.exit_code == 0
35493549
mock_run_command.assert_called_once_with(['acl-loader', 'update', 'incremental', file_name])
35503550

3551-
def teardown(self):
3551+
def teardown_method(self):
35523552
print("TEARDOWN")
35533553

35543554

35553555
class TestConfigDropcounters(object):
3556-
def setup(self):
3556+
def setup_method(self):
35573557
print("SETUP")
35583558

35593559
@patch('utilities_common.cli.run_command')
@@ -3620,12 +3620,12 @@ def test_remove_reasons(self, mock_run_command):
36203620
assert result.exit_code == 0
36213621
mock_run_command.assert_called_once_with(['dropconfig', '-c', 'remove', '-n', str(counter_name), '-r', str(reasons)], display_cmd=True)
36223622

3623-
def teardown(self):
3623+
def teardown_method(self):
36243624
print("TEARDOWN")
36253625

36263626

36273627
class TestConfigDropcountersMasic(object):
3628-
def setup(self):
3628+
def setup_method(self):
36293629
print("SETUP")
36303630
os.environ['UTILITIES_UNIT_TESTING'] = "1"
36313631
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic"
@@ -3746,7 +3746,7 @@ def teardown_class(cls):
37463746
dbconnector.load_namespace_config()
37473747

37483748
class TestConfigWatermarkTelemetry(object):
3749-
def setup(self):
3749+
def setup_method(self):
37503750
print("SETUP")
37513751

37523752
@patch('utilities_common.cli.run_command')
@@ -3759,12 +3759,12 @@ def test_interval(self, mock_run_command):
37593759
assert result.exit_code == 0
37603760
mock_run_command.assert_called_once_with(['watermarkcfg', '--config-interval', str(interval)])
37613761

3762-
def teardown(self):
3762+
def teardown_method(self):
37633763
print("TEARDOWN")
37643764

37653765

37663766
class TestConfigZtp(object):
3767-
def setup(self):
3767+
def setup_method(self):
37683768
print("SETUP")
37693769

37703770
@patch('utilities_common.cli.run_command')
@@ -3794,7 +3794,7 @@ def test_enable(self, mock_run_command):
37943794
assert result.exit_code == 0
37953795
mock_run_command.assert_called_once_with(['ztp', 'enable'], display_cmd=True)
37963796

3797-
def teardown(self):
3797+
def teardown_method(self):
37983798
print("TEARDOWN")
37993799

38003800

@@ -3820,7 +3820,7 @@ def test_change_hostname(mock_run_command):
38203820

38213821

38223822
class TestConfigInterface(object):
3823-
def setup(self):
3823+
def setup_method(self):
38243824
print("SETUP")
38253825

38263826
@patch('utilities_common.cli.run_command')
@@ -3960,7 +3960,7 @@ def test_startup_shutdown_loopback(self):
39603960
assert result.exit_code == 0
39613961
assert db.cfgdb.get_table('LOOPBACK_INTERFACE')['Loopback0']['admin_status'] == 'up'
39623962

3963-
def teardown(self):
3963+
def teardown_method(self):
39643964
print("TEARDOWN")
39653965

39663966

tests/disk_check_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def swap_work(tc):
126126

127127

128128
class TestDiskCheck(object):
129-
def setup(self):
129+
def setup_method(self):
130130
pass
131131

132132

tests/dropconfig_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
dropconfig = load_module_from_source('dropconfig', dropconfig_path)
1212

1313
class TestDropConfig(object):
14-
def setup(self):
14+
def setup_method(self):
1515
print('SETUP')
1616

1717
@patch('builtins.print')
@@ -169,5 +169,5 @@ def test_invalid_dct_enable_monitor_error(self, mock_print):
169169
mock_print.assert_called_once_with(err_msg)
170170
assert e.value.code == 1
171171

172-
def teardown(self):
172+
def teardown_method(self):
173173
print('TEARDOWN')

tests/fast_reboot_filter_routes_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fast_reboot_filter_routes = importlib.import_module("scripts.fast-reboot-filter-routes")
66

77
class TestFastRebootFilterRoutes(object):
8-
def setup(self):
8+
def setup_method(self):
99
print("SETUP")
1010

1111
@patch('utilities_common.cli.run_command')
@@ -22,5 +22,5 @@ def test_get_connected_routes_command_failed(self, mock_run_command):
2222
fast_reboot_filter_routes.get_connected_routes()
2323
mock_run_command.assert_called_with(['sudo', 'vtysh', '-c', "show ip route connected json"], return_cmd=True)
2424

25-
def teardown(self):
25+
def teardown_method(self):
2626
print("TEAR DOWN")

tests/flock_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def dummy_f2(bypass_lock=True):
2828

2929

3030
class TestFLock:
31-
def setup(self):
31+
def setup_method(self):
3232
print("SETUP")
3333
f0_exit.clear()
3434
f1_exit.clear()
@@ -180,7 +180,7 @@ def get_file_content(fd):
180180
f2_exit.set()
181181
thrd.join()
182182

183-
def teardown(self):
183+
def teardown_method(self):
184184
print("TEARDOWN")
185185
f0_exit.clear()
186186
f1_exit.clear()

tests/fwutil_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import fwutil.lib as fwutil_lib
88

99
class TestSquashFs(object):
10-
def setup(self):
10+
def setup_method(self):
1111
print('SETUP')
1212

1313
@patch('fwutil.lib.check_output_pipe')
@@ -75,12 +75,12 @@ def test_unmount_next_image_fs(self, mock_check_call, mock_exists, mock_rmdir):
7575
call(sqfs.fs_mountpoint)
7676
]
7777

78-
def teardown(self):
78+
def teardown_method(self):
7979
print('TEARDOWN')
8080

8181

8282
class TestComponentUpdateProvider(object):
83-
def setup(self):
83+
def setup_method(self):
8484
print('SETUP')
8585

8686
@patch("glob.glob", MagicMock(side_effect=[[], ['abc'], [], ['abc']]))
@@ -242,7 +242,7 @@ def test_regular_chassis_module_validation_error(self, mock_mkdir, mock_validate
242242
)
243243
assert "Module names mismatch" in str(excinfo.value)
244244

245-
def teardown(self):
245+
def teardown_method(self):
246246
print('TEARDOWN')
247247

248248

tests/route_check_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def extract_namespace_from_args(args):
216216
return args[i + 1]
217217
return DEFAULTNS
218218

219-
def setup(self):
219+
def setup_method(self):
220220
pass
221221

222222
def init(self):

tests/show_barefoot_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class TestShowBarefoot(object):
10-
def setup(self):
10+
def setup_method(self):
1111
print('SETUP')
1212

1313
@patch('subprocess.run')
@@ -48,6 +48,6 @@ def test_nondefault_profile(self, mock_run, mock_cmd):
4848
mock_open_file.assert_called_once_with('/usr/share/sonic/hwsku_dir/switch-tna-sai.conf')
4949
assert mock_cmd.call_args_list == expected_calls
5050

51-
def teardown(self):
51+
def teardown_method(self):
5252
print('TEARDOWN')
5353

tests/show_mlnx_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class TestShowMlnx(object):
9-
def setup(self):
9+
def setup_method(self):
1010
print('SETUP')
1111

1212
@patch('click.style')
@@ -113,6 +113,6 @@ def mock_return(*args, **kwargs):
113113
result = show.is_issu_status_enabled()
114114
assert result is status
115115

116-
def teardown(self):
116+
def teardown_method(self):
117117
print('TEARDOWN')
118118

0 commit comments

Comments
 (0)