File tree Expand file tree Collapse file tree 3 files changed +21
-17
lines changed Expand file tree Collapse file tree 3 files changed +21
-17
lines changed Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
"""Test deprecated functionality which will be removed in vX.Y.Z"""
15
15
import sys
16
- from contextlib import contextmanager
17
-
18
- import pytest
19
16
20
17
21
18
def _soft_unimport_module (str_module ):
22
19
# once the module is imported e.g with parsing with pytest it lives in memory
23
20
if str_module in sys .modules :
24
21
del sys .modules [str_module ]
25
-
26
-
27
- @contextmanager
28
- def no_deprecated_call ():
29
- with pytest .warns (None ) as record :
30
- yield
31
- try :
32
- w = record .pop (DeprecationWarning )
33
- except AssertionError :
34
- # no DeprecationWarning raised
35
- return
36
- raise AssertionError (f"`DeprecationWarning` was raised: { w } " )
Original file line number Diff line number Diff line change 16
16
import pytest
17
17
18
18
from pytorch_lightning import Trainer , Callback
19
- from tests .deprecated_api import no_deprecated_call
20
19
from tests .helpers import BoringModel
20
+ from tests .helpers .utils import no_warning_call
21
21
22
22
23
23
def test_v1_5_0_old_callback_on_save_checkpoint (tmpdir ):
@@ -52,5 +52,5 @@ def on_save_checkpoint(self, *args):
52
52
...
53
53
54
54
trainer .callbacks = [NewSignature (), ValidSignature1 (), ValidSignature2 ()]
55
- with no_deprecated_call ( ):
55
+ with no_warning_call ( DeprecationWarning ):
56
56
trainer .save_checkpoint (filepath )
Original file line number Diff line number Diff line change 14
14
import functools
15
15
import os
16
16
import traceback
17
+ from contextlib import contextmanager
18
+ from typing import Optional
19
+
20
+ import pytest
17
21
18
22
from pytorch_lightning import seed_everything
19
23
from pytorch_lightning .callbacks import ModelCheckpoint
@@ -111,3 +115,18 @@ def inner_f(queue, **kwargs):
111
115
assert result == 1 , 'expected 1, but returned %s' % result
112
116
113
117
return wrapper
118
+
119
+
120
+ @contextmanager
121
+ def no_warning_call (warning_type , match : Optional [str ] = None ):
122
+ with pytest .warns (None ) as record :
123
+ yield
124
+
125
+ try :
126
+ w = record .pop (warning_type )
127
+ if not ((match and match in w .text ) or w ):
128
+ return
129
+ except AssertionError :
130
+ # no warning raised
131
+ return
132
+ raise AssertionError (f"`{ warning_type } ` was raised: { w } " )
You can’t perform that action at this time.
0 commit comments