Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX New pytest version errors on warning test #1056

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions skorch/tests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down
Loading