@@ -144,26 +144,22 @@ def test_old_call_convention(self):
144144
145145 def test_new_call_convention (self ):
146146 """This is how it should be called now."""
147- warnings .simplefilter ("always" )
148- with pytest .warns (None ) as warns :
147+ # make sure no warnings are raised
148+ with warnings .catch_warnings ():
149+ warnings .simplefilter ("error" )
149150 der = encode_bitstring (b"\xff " , 0 )
150151
151- # verify that new call convention doesn't raise Warnings
152- self .assertEqual (len (warns ), 0 )
153-
154152 self .assertEqual (der , b"\x03 \x02 \x00 \xff " )
155153
156154 def test_implicit_unused_bits (self ):
157155 """
158156 Writing bit string with already included the number of unused bits.
159157 """
160- warnings .simplefilter ("always" )
161- with pytest .warns (None ) as warns :
158+ # make sure no warnings are raised
159+ with warnings .catch_warnings ():
160+ warnings .simplefilter ("error" )
162161 der = encode_bitstring (b"\x00 \xff " , None )
163162
164- # verify that new call convention doesn't raise Warnings
165- self .assertEqual (len (warns ), 0 )
166-
167163 self .assertEqual (der , b"\x03 \x02 \x00 \xff " )
168164
169165 def test_explicit_unused_bits (self ):
@@ -203,22 +199,20 @@ def test_old_call_convention(self):
203199 self .assertEqual (rest , b"" )
204200
205201 def test_new_call_convention (self ):
206- warnings .simplefilter ("always" )
207- with pytest .warns (None ) as warns :
202+ # make sure no warnings are raised
203+ with warnings .catch_warnings ():
204+ warnings .simplefilter ("error" )
208205 bits , rest = remove_bitstring (b"\x03 \x02 \x00 \xff " , 0 )
209206
210- self .assertEqual (len (warns ), 0 )
211-
212207 self .assertEqual (bits , b"\xff " )
213208 self .assertEqual (rest , b"" )
214209
215210 def test_implicit_unexpected_unused (self ):
216- warnings .simplefilter ("always" )
217- with pytest .warns (None ) as warns :
211+ # make sure no warnings are raised
212+ with warnings .catch_warnings ():
213+ warnings .simplefilter ("error" )
218214 bits , rest = remove_bitstring (b"\x03 \x02 \x00 \xff " , None )
219215
220- self .assertEqual (len (warns ), 0 )
221-
222216 self .assertEqual (bits , (b"\xff " , 0 ))
223217 self .assertEqual (rest , b"" )
224218
0 commit comments