Skip to content

Commit

Permalink
Get rid of deprecated pytest.warns(expected_warning=None) usage (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
Taragolis authored Mar 16, 2024
1 parent 191036b commit ed920a0
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit ed920a0

Please sign in to comment.