@@ -40,18 +40,6 @@ def deprecated_method() -> None:
4040 )
4141
4242
43- @patch ("warnings.warn" )
44- def test_deprecation_message (warn : Mock ) -> None :
45- deprecation_message (
46- deprecated_in = "0.1.0" ,
47- removed_in = "0.2.0" ,
48- help_message = "Please use something_else instead" ,
49- )
50-
51- assert warn .called
52- assert warn .call_args [0 ] == ("Deprecated in 0.1.0, will be removed in 0.2.0. Please use something_else instead" ,)
53-
54-
5543@patch ("warnings.warn" )
5644def test_deprecated_without_help_message (warn : Mock ) -> None :
5745 @deprecated (
@@ -67,21 +55,19 @@ def deprecated_method() -> None:
6755 assert warn .call_args [0 ] == ("Call to deprecated_method, deprecated in 0.1.0, will be removed in 0.2.0." ,)
6856
6957
70- @patch ("warnings.warn" )
71- def test_deprecation_message_without_help_message (warn : Mock ) -> None :
72- deprecation_message (
73- deprecated_in = "0.1.0" ,
74- removed_in = "0.2.0" ,
75- help_message = None ,
76- )
58+ def test_deprecated_warning_points_at_the_caller () -> None :
59+ """The warning is attributed to the code using the deprecated API, not to the helper."""
7760
78- assert warn .called
79- assert warn .call_args [0 ] == ("Deprecated in 0.1.0, will be removed in 0.2.0." ,)
61+ @deprecated (deprecated_in = "0.1.0" , removed_in = "0.2.0" )
62+ def deprecated_method () -> None :
63+ pass
8064
65+ with warnings .catch_warnings (record = True ) as caught :
66+ warnings .simplefilter ("always" )
67+ deprecated_method ()
8168
82- @pytest .mark .parametrize ("help_message" , [None , "" ])
83- def test_deprecation_notice_without_help_message (help_message : str | None ) -> None :
84- assert deprecation_notice ("0.1.0" , "0.2.0" , help_message ) == "Deprecated in 0.1.0, will be removed in 0.2.0."
69+ assert len (caught ) == 1
70+ assert caught [0 ].filename == __file__
8571
8672
8773def test_deprecation_notice_with_help_message () -> None :
@@ -91,19 +77,33 @@ def test_deprecation_notice_with_help_message() -> None:
9177 )
9278
9379
94- def test_deprecated_warning_points_at_the_caller () -> None :
95- """The warning is attributed to the code using the deprecated API, not to the helper."""
80+ @pytest .mark .parametrize ("help_message" , [None , "" ])
81+ def test_deprecation_notice_without_help_message (help_message : str | None ) -> None :
82+ assert deprecation_notice ("0.1.0" , "0.2.0" , help_message ) == "Deprecated in 0.1.0, will be removed in 0.2.0."
9683
97- @deprecated (deprecated_in = "0.1.0" , removed_in = "0.2.0" )
98- def deprecated_method () -> None :
99- pass
10084
101- with warnings .catch_warnings (record = True ) as caught :
102- warnings .simplefilter ("always" )
103- deprecated_method ()
85+ @patch ("warnings.warn" )
86+ def test_deprecation_message (warn : Mock ) -> None :
87+ deprecation_message (
88+ deprecated_in = "0.1.0" ,
89+ removed_in = "0.2.0" ,
90+ help_message = "Please use something_else instead" ,
91+ )
10492
105- assert len (caught ) == 1
106- assert caught [0 ].filename == __file__
93+ assert warn .called
94+ assert warn .call_args [0 ] == ("Deprecated in 0.1.0, will be removed in 0.2.0. Please use something_else instead" ,)
95+
96+
97+ @patch ("warnings.warn" )
98+ def test_deprecation_message_without_help_message (warn : Mock ) -> None :
99+ deprecation_message (
100+ deprecated_in = "0.1.0" ,
101+ removed_in = "0.2.0" ,
102+ help_message = None ,
103+ )
104+
105+ assert warn .called
106+ assert warn .call_args [0 ] == ("Deprecated in 0.1.0, will be removed in 0.2.0." ,)
107107
108108
109109def test_deprecation_message_points_at_the_caller () -> None :
0 commit comments