Skip to content

Commit cddf942

Browse files
committed
[Test] Fix ut of runner
1 parent ad8b15a commit cddf942

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

tests/test_runner/test_checkpoint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def load_from_abc(filename, map_location):
354354
assert loader.__name__ == 'load_from_abc'
355355

356356

357+
@patch.dict(sys.modules, {'petrel_client': MagicMock()})
357358
def test_save_checkpoint(tmp_path):
358359
model = Model()
359360
optimizer = optim.SGD(model.parameters(), lr=0.1, momentum=0.9)

tests/test_runner/test_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ def test_checkpoint(self):
22722272
self.assertTrue(osp.exists(path))
22732273
self.assertFalse(osp.exists(osp.join(self.temp_dir, 'epoch_4.pth')))
22742274

2275-
ckpt = torch.load(path)
2275+
ckpt = torch.load(path, weights_only=False)
22762276
self.assertEqual(ckpt['meta']['epoch'], 3)
22772277
self.assertEqual(ckpt['meta']['iter'], 12)
22782278
self.assertEqual(ckpt['meta']['experiment_name'],
@@ -2444,7 +2444,7 @@ def test_checkpoint(self):
24442444
self.assertTrue(osp.exists(path))
24452445
self.assertFalse(osp.exists(osp.join(self.temp_dir, 'epoch_13.pth')))
24462446

2447-
ckpt = torch.load(path)
2447+
ckpt = torch.load(path, weights_only=False)
24482448
self.assertEqual(ckpt['meta']['epoch'], 0)
24492449
self.assertEqual(ckpt['meta']['iter'], 12)
24502450
assert isinstance(ckpt['optimizer'], dict)
@@ -2455,7 +2455,7 @@ def test_checkpoint(self):
24552455
self.assertEqual(message_hub.get_info('iter'), 11)
24562456
# 2.1.2 check class attribute _statistic_methods can be saved
24572457
HistoryBuffer._statistics_methods.clear()
2458-
ckpt = torch.load(path)
2458+
ckpt = torch.load(path, weights_only=False)
24592459
self.assertIn('min', HistoryBuffer._statistics_methods)
24602460

24612461
# 2.2 test `load_checkpoint`

0 commit comments

Comments
 (0)