From 5b64bee00d5d882a40f7549f0b8ed21a7ea23bd5 Mon Sep 17 00:00:00 2001 From: fanqiNO1 <1848839264@qq.com> Date: Sun, 18 Feb 2024 12:17:39 +0800 Subject: [PATCH] [Fix] Fix warning capture --- tests/test_utils/test_dl_utils/test_torch_ops.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_utils/test_dl_utils/test_torch_ops.py b/tests/test_utils/test_dl_utils/test_torch_ops.py index 03e5decf0d..7d2f2b5b8d 100644 --- a/tests/test_utils/test_dl_utils/test_torch_ops.py +++ b/tests/test_utils/test_dl_utils/test_torch_ops.py @@ -1,6 +1,5 @@ # Copyright (c) OpenMMLab. All rights reserved. -import warnings - +import pytest import torch from mmengine.utils.dl_utils import torch_meshgrid @@ -8,8 +7,8 @@ def test_torch_meshgrid(): # torch_meshgrid should not throw warning - with warnings.catch_warnings(): - warnings.simplefilter('error') + with pytest.warns(UserWarning) as record: x = torch.tensor([1, 2, 3]) y = torch.tensor([4, 5, 6]) grid_x, grid_y = torch_meshgrid(x, y) + assert len(record) == 0