From dd341d3b53879d4216225d430b9da6f708a7341d Mon Sep 17 00:00:00 2001 From: Benjamin Bossan Date: Mon, 27 May 2024 16:59:28 +0200 Subject: [PATCH] FIX New pytest version errors on warning test (#1056) We had a test that basically called pytest.warns(None), which newer pytest versions don't allow. Instead, now using recwarn to assert that there is _no_ error. The suggested pytest.does_not_warn() (https://github.com/pytest-dev/pytest/issues/9404) does not appear to work. --- skorch/tests/test_net.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/skorch/tests/test_net.py b/skorch/tests/test_net.py index 410fd7b6f..7eec94e5a 100644 --- a/skorch/tests/test_net.py +++ b/skorch/tests/test_net.py @@ -468,6 +468,7 @@ def test_pickle_save_and_load_mixed_devices( cuda_available, load_dev, expect_warning, + recwarn, ): from skorch.exceptions import DeviceWarning net = net_cls(module=module_cls, device=save_dev).initialize() @@ -479,9 +480,12 @@ def test_pickle_save_and_load_mixed_devices( with patch('torch.cuda.is_available', lambda *_: cuda_available): with open(str(p), 'rb') as f: - expected_warning = DeviceWarning if expect_warning else None - with pytest.warns(expected_warning) as w: + if not expect_warning: m = pickle.load(f) + assert not recwarn.list + else: + with pytest.warns(DeviceWarning) as w: + m = pickle.load(f) assert torch.device(m.device) == torch.device(load_dev)