Skip to content

Commit f7a0eaa

Browse files
authored
Get rid of deprecated pytest.warns(None) usage (#38027)
1 parent c6f3439 commit f7a0eaa

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

tests/providers/amazon/aws/hooks/test_emr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
import re
21+
import warnings
2122
from unittest import mock
2223

2324
import boto3
@@ -167,7 +168,9 @@ def test_create_job_flow_extra_args(self):
167168
# AmiVersion is really old and almost no one will use it anymore, but
168169
# it's one of the "optional" request params that moto supports - it's
169170
# coverage of EMR isn't 100% it turns out.
170-
with pytest.warns(None): # Expected no warnings if ``emr_conn_id`` exists with correct conn_type
171+
with warnings.catch_warnings():
172+
# Expected no warnings if ``emr_conn_id`` exists with correct conn_type
173+
warnings.simplefilter("error")
171174
cluster = hook.create_job_flow({"Name": "test_cluster", "ReleaseLabel": "", "AmiVersion": "3.2"})
172175
cluster = client.describe_cluster(ClusterId=cluster["JobFlowId"])["Cluster"]
173176

tests/providers/amazon/aws/utils/test_connection_wrapper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import os
20+
import warnings
2021
from dataclasses import fields
2122
from unittest import mock
2223

@@ -237,7 +238,8 @@ def test_get_session_kwargs_from_wrapper(
237238
expected["profile_name"] = profile_name
238239
if region_name:
239240
expected["region_name"] = region_name
240-
with pytest.warns(None):
241+
with warnings.catch_warnings():
242+
warnings.simplefilter("error") # Not expected any warnings here
241243
wrap_conn = AwsConnectionWrapper(conn=mock_conn)
242244
session_kwargs = wrap_conn.session_kwargs
243245
assert session_kwargs == expected
@@ -354,7 +356,7 @@ def test_get_endpoint_url_from_extra(self, extra, expected):
354356
" Please set extra['endpoint_url'] instead"
355357
)
356358

357-
with pytest.warns(None) as records:
359+
with warnings.catch_warnings(record=True) as records:
358360
wrap_conn = AwsConnectionWrapper(conn=mock_conn)
359361

360362
if extra.get("host"):

tests/www/test_init_views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import re
20+
import warnings
2021
from unittest import mock
2122

2223
import pytest
@@ -37,6 +38,6 @@ def test_should_raise_deprecation_warning_when_enabled(self):
3738
@conf_vars({("api", "enable_experimental_api"): "false"})
3839
def test_should_not_raise_deprecation_warning_when_disabled(self):
3940
app = mock.MagicMock()
40-
with pytest.warns(None) as warnings:
41+
with warnings.catch_warnings():
42+
warnings.simplefilter("error") # Not expected any warnings here
4143
init_views.init_api_experimental(app)
42-
assert len(warnings) == 0

0 commit comments

Comments
 (0)