1313# limitations under the License.
1414
1515import sys
16- import warnings
1716
1817import grpc
1918
@@ -218,7 +217,7 @@ def test_context_manager_raises_if_closed(creds):
218217def test_api_property_deprecated (creds ):
219218 client = subscriber .Client (credentials = creds )
220219
221- with warnings . catch_warnings ( record = True ) as warned :
220+ with pytest . warns ( DeprecationWarning , match = "client.api" ) as warned :
222221 client .api
223222
224223 assert len (warned ) == 1
@@ -230,7 +229,7 @@ def test_api_property_deprecated(creds):
230229def test_api_property_proxy_to_generated_client (creds ):
231230 client = subscriber .Client (credentials = creds )
232231
233- with warnings . catch_warnings ( record = True ):
232+ with pytest . warns ( DeprecationWarning , match = "client.api" ):
234233 api_object = client .api
235234
236235 # Not a perfect check, but we are satisficed if the returned API object indeed
@@ -262,9 +261,10 @@ def test_sync_pull_warning_if_return_immediately(creds):
262261 client = subscriber .Client (credentials = creds )
263262 subscription_path = "projects/foo/subscriptions/bar"
264263
265- with mock .patch .object (
266- client ._transport , "_wrapped_methods"
267- ), warnings .catch_warnings (record = True ) as warned :
264+ with mock .patch .object (client ._transport , "_wrapped_methods" ), pytest .warns (
265+ DeprecationWarning ,
266+ match = "The return_immediately flag is deprecated and should be set to False" ,
267+ ) as warned :
268268 client .pull (subscription = subscription_path , return_immediately = True )
269269
270270 # Setting the deprecated return_immediately flag to True should emit a warning.
@@ -287,7 +287,10 @@ async def test_sync_pull_warning_if_return_immediately_async(creds):
287287 new = mock .AsyncMock ,
288288 )
289289
290- with patcher , warnings .catch_warnings (record = True ) as warned :
290+ with patcher , pytest .warns (
291+ DeprecationWarning ,
292+ match = "The return_immediately flag is deprecated and should be set to False" ,
293+ ) as warned :
291294 await client .pull (subscription = subscription_path , return_immediately = True )
292295
293296 # Setting the deprecated return_immediately flag to True should emit a warning.
0 commit comments