Skip to content

Commit 425691b

Browse files
authored
test: Use mark.filterwarnings (#449)
1 parent a33485e commit 425691b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

tests/doc/test_rst.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
functions here to test them.
55
"""
66

7+
from pytest import mark
8+
79

810
def test_amp():
911
import torch
@@ -198,12 +200,13 @@ def test_autogram():
198200
test_autogram()
199201

200202

203+
@mark.filterwarnings(
204+
"ignore::DeprecationWarning", "ignore::lightning.fabric.utilities.warnings.PossibleUserWarning"
205+
)
201206
def test_lightning_integration():
202207
# Extra ----------------------------------------------------------------------------------------
203208
import logging
204-
import warnings
205209

206-
warnings.filterwarnings("ignore")
207210
logging.disable(logging.INFO)
208211
# ----------------------------------------------------------------------------------------------
209212

tests/unit/aggregation/test_values.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import warnings
2-
3-
from pytest import mark
1+
from pytest import mark, param
42
from torch import Tensor, tensor
53
from torch.testing import assert_close
64

@@ -98,7 +96,12 @@
9896
from torchjd.aggregation import NashMTL
9997

10098
AGGREGATOR_PARAMETRIZATIONS.append(
101-
(NashMTL(n_tasks=2), J_base, tensor([0.0542, 0.7061, 0.7061]))
99+
param(
100+
NashMTL(n_tasks=2),
101+
J_base,
102+
tensor([0.0542, 0.7061, 0.7061]),
103+
marks=mark.filterwarnings("ignore::UserWarning"),
104+
)
102105
)
103106

104107
except ImportError:
@@ -109,9 +112,6 @@
109112
def test_aggregator_output(A: Aggregator, J: Tensor, expected_output: Tensor):
110113
"""Test that the output values of an aggregator are fixed (on cpu)."""
111114

112-
if str(A).startswith("NashMTL"):
113-
warnings.filterwarnings("ignore")
114-
115115
assert_close(A(J), expected_output, rtol=0, atol=1e-4)
116116

117117

0 commit comments

Comments
 (0)