Skip to content

Commit

Permalink
Get rid of deprecated pytest.warns(None) usage (apache#38027)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taragolis authored and utkarsharma2 committed Apr 22, 2024
1 parent ad4660a commit 306e00f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tests/providers/amazon/aws/hooks/test_emr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import re
import warnings
from unittest import mock

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

Expand Down
6 changes: 4 additions & 2 deletions tests/providers/amazon/aws/utils/test_connection_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from __future__ import annotations

import os
import warnings
from dataclasses import fields
from unittest import mock

Expand Down Expand Up @@ -237,7 +238,8 @@ def test_get_session_kwargs_from_wrapper(
expected["profile_name"] = profile_name
if region_name:
expected["region_name"] = region_name
with pytest.warns(None):
with warnings.catch_warnings():
warnings.simplefilter("error") # Not expected any warnings here
wrap_conn = AwsConnectionWrapper(conn=mock_conn)
session_kwargs = wrap_conn.session_kwargs
assert session_kwargs == expected
Expand Down Expand Up @@ -354,7 +356,7 @@ def test_get_endpoint_url_from_extra(self, extra, expected):
" Please set extra['endpoint_url'] instead"
)

with pytest.warns(None) as records:
with warnings.catch_warnings(record=True) as records:
wrap_conn = AwsConnectionWrapper(conn=mock_conn)

if extra.get("host"):
Expand Down
5 changes: 3 additions & 2 deletions tests/www/test_init_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from __future__ import annotations

import re
import warnings
from unittest import mock

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

0 comments on commit 306e00f

Please sign in to comment.