Skip to content

Commit

Permalink
FIX New pytest version errors on warning test (#1056)
Browse files Browse the repository at this point in the history
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() (pytest-dev/pytest#9404)
does not appear to work.
  • Loading branch information
BenjaminBossan authored May 27, 2024
1 parent bc198b9 commit dd341d3
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit dd341d3

Please sign in to comment.