Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of deprecated pytest.warns(expected_warning=None) usage #38203

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tests/always/test_providers_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import logging
import re
import sys
import warnings
from pathlib import Path
from unittest.mock import patch

Expand Down Expand Up @@ -73,7 +74,7 @@ def test_hooks_deprecation_warnings_generated(self):
assert warning_records

def test_hooks_deprecation_warnings_not_generated(self):
with pytest.warns(expected_warning=None) as warning_records:
with warnings.catch_warnings(record=True) as warning_records:
providers_manager = ProvidersManager()
providers_manager._provider_dict["apache-airflow-providers-sftp"] = ProviderInfo(
version="0.0.1",
Expand All @@ -89,7 +90,7 @@ def test_hooks_deprecation_warnings_not_generated(self):
package_or_source="package",
)
providers_manager._discover_hooks()
assert [] == [w.message for w in warning_records.list if "hook-class-names" in str(w.message)]
assert [] == [w.message for w in warning_records if "hook-class-names" in str(w.message)]

def test_warning_logs_generated(self):
providers_manager = ProvidersManager()
Expand Down Expand Up @@ -187,7 +188,7 @@ def test_providers_manager_register_plugins(self):
)

def test_hooks(self):
with pytest.warns(expected_warning=None) as warning_records:
with warnings.catch_warnings(record=True) as warning_records:
with self._caplog.at_level(logging.WARNING):
provider_manager = ProvidersManager()
connections_list = list(provider_manager.hooks.keys())
Expand All @@ -197,7 +198,7 @@ def test_hooks(self):
print(record.message, file=sys.stderr)
print(record.exc_info, file=sys.stderr)
raise AssertionError("There are warnings generated during hook imports. Please fix them")
assert [] == [w.message for w in warning_records.list if "hook-class-names" in str(w.message)]
assert [] == [w.message for w in warning_records if "hook-class-names" in str(w.message)]

@pytest.mark.execution_timeout(150)
def test_hook_values(self):
Expand All @@ -209,7 +210,7 @@ def test_hook_values(self):
for provider_name, provider_info in provider_dependencies.items():
if python_version in provider_info.get("excluded-python-versions", []):
excluded_providers.append(f"apache-airflow-providers-{provider_name.replace('.', '-')}")
with pytest.warns(expected_warning=None) as warning_records:
with warnings.catch_warnings(record=True) as warning_records:
with self._caplog.at_level(logging.WARNING):
provider_manager = ProvidersManager()
connections_list = list(provider_manager.hooks.values())
Expand All @@ -226,7 +227,7 @@ def test_hook_values(self):
real_warning_count += 1
if real_warning_count:
raise AssertionError("There are warnings generated during hook imports. Please fix them")
assert [] == [w.message for w in warning_records.list if "hook-class-names" in str(w.message)]
assert [] == [w.message for w in warning_records if "hook-class-names" in str(w.message)]

def test_connection_form_widgets(self):
provider_manager = ProvidersManager()
Expand Down