This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new dd97086416 Resolve PT012 in `microsoft.azure`, `microsoft.psrp`, and 
`oracle` providers tests (#38436)
dd97086416 is described below

commit dd9708641600425012afed38d8a3150c48b79b09
Author: Andrey Anshin <[email protected]>
AuthorDate: Sun Mar 24 16:13:45 2024 +0400

    Resolve PT012 in `microsoft.azure`, `microsoft.psrp`, and `oracle` 
providers tests (#38436)
---
 pyproject.toml                                             |  4 ----
 tests/providers/microsoft/azure/hooks/test_data_factory.py |  4 ++--
 tests/providers/microsoft/azure/hooks/test_wasb.py         | 11 +++++------
 tests/providers/microsoft/psrp/hooks/test_psrp.py          |  3 ++-
 tests/providers/oracle/hooks/test_oracle.py                |  8 ++++----
 5 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 43f530e18c..643636ae2a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1543,10 +1543,6 @@ combine-as-imports = true
 "tests/providers/google/cloud/transfers/test_gcs_to_bigquery.py" = ["PT012"]
 "tests/providers/google/cloud/utils/test_credentials_provider.py" = ["PT012"]
 "tests/providers/google/common/hooks/test_base_google.py" = ["PT012"]
-"tests/providers/microsoft/azure/hooks/test_data_factory.py" = ["PT012"]
-"tests/providers/microsoft/azure/hooks/test_wasb.py" = ["PT012"]
-"tests/providers/microsoft/psrp/hooks/test_psrp.py" = ["PT012"]
-"tests/providers/oracle/hooks/test_oracle.py" = ["PT012"]
 "tests/providers/sftp/hooks/test_sftp.py" = ["PT012"]
 "tests/providers/sftp/operators/test_sftp.py" = ["PT012"]
 "tests/providers/sftp/sensors/test_sftp.py" = ["PT012"]
diff --git a/tests/providers/microsoft/azure/hooks/test_data_factory.py 
b/tests/providers/microsoft/azure/hooks/test_data_factory.py
index 316ce01973..1ee77ad3af 100644
--- a/tests/providers/microsoft/azure/hooks/test_data_factory.py
+++ b/tests/providers/microsoft/azure/hooks/test_data_factory.py
@@ -163,8 +163,8 @@ def test_provide_targeted_factory():
     assert provide_targeted_factory(echo)(hook, None, FACTORY) == 
(DEFAULT_RESOURCE_GROUP, FACTORY)
     assert provide_targeted_factory(echo)(hook, None, None) == 
(DEFAULT_RESOURCE_GROUP, DEFAULT_FACTORY)
 
-    with pytest.raises(AirflowException):
-        conn.extra_dejson = {}
+    conn.extra_dejson = {}
+    with pytest.raises(AirflowException, match="Could not determine the 
targeted data factory"):
         provide_targeted_factory(echo)(hook)
 
 
diff --git a/tests/providers/microsoft/azure/hooks/test_wasb.py 
b/tests/providers/microsoft/azure/hooks/test_wasb.py
index 7fb4d7d8f9..51b4c94a92 100644
--- a/tests/providers/microsoft/azure/hooks/test_wasb.py
+++ b/tests/providers/microsoft/azure/hooks/test_wasb.py
@@ -17,6 +17,7 @@
 # under the License.
 from __future__ import annotations
 
+import re
 from unittest import mock
 
 import pytest
@@ -584,18 +585,16 @@ class TestWasbHook:
     def test_delete_nonexisting_blob_fails(self, mock_check, mock_getblobs, 
mocked_blob_service_client):
         mock_getblobs.return_value = []
         mock_check.return_value = False
-        with pytest.raises(Exception) as ctx:
-            hook = WasbHook(wasb_conn_id=self.azure_shared_key_test)
+        hook = WasbHook(wasb_conn_id=self.azure_shared_key_test)
+        with pytest.raises(AirflowException, match=re.escape("Blob(s) not 
found: nonexisting_blob")):
             hook.delete_file("container", "nonexisting_blob", is_prefix=False, 
ignore_if_missing=False)
-        assert isinstance(ctx.value, AirflowException)
 
     @mock.patch.object(WasbHook, "get_blobs_list")
     def test_delete_multiple_nonexisting_blobs_fails(self, mock_getblobs):
         mock_getblobs.return_value = []
-        with pytest.raises(Exception) as ctx:
-            hook = WasbHook(wasb_conn_id=self.azure_shared_key_test)
+        hook = WasbHook(wasb_conn_id=self.azure_shared_key_test)
+        with pytest.raises(AirflowException, match=re.escape("Blob(s) not 
found: nonexisting_blob_prefix")):
             hook.delete_file("container", "nonexisting_blob_prefix", 
is_prefix=True, ignore_if_missing=False)
-        assert isinstance(ctx.value, AirflowException)
 
     def test_connection_success(self, mocked_blob_service_client):
         hook = WasbHook(wasb_conn_id=self.azure_shared_key_test)
diff --git a/tests/providers/microsoft/psrp/hooks/test_psrp.py 
b/tests/providers/microsoft/psrp/hooks/test_psrp.py
index 4762cfd240..9a2c2b0b55 100644
--- a/tests/providers/microsoft/psrp/hooks/test_psrp.py
+++ b/tests/providers/microsoft/psrp/hooks/test_psrp.py
@@ -146,7 +146,8 @@ class TestPsrpHook:
             on_output_callback=on_output_callback,
             **options,
         ) as hook, patch.object(type(hook), "log") as logger:
-            with pytest.raises(AirflowException, match="Process had one or 
more errors"):
+            error_match = "Process had one or more errors"
+            with pytest.raises(AirflowException, match=error_match):  # noqa: 
PT012 error happen on context exit
                 with hook.invoke() as ps:
                     assert ps.state == PSInvocationState.NOT_STARTED
 
diff --git a/tests/providers/oracle/hooks/test_oracle.py 
b/tests/providers/oracle/hooks/test_oracle.py
index fa40ffcccb..4bfbbaddf6 100644
--- a/tests/providers/oracle/hooks/test_oracle.py
+++ b/tests/providers/oracle/hooks/test_oracle.py
@@ -245,15 +245,15 @@ class TestOracleHookConn:
         assert oracledb.defaults.fetch_lobs is False
 
     def test_type_checking_thick_mode_lib_dir(self):
+        thick_mode_lib_dir_test = {"thick_mode": True, "thick_mode_lib_dir": 1}
+        self.connection.extra = json.dumps(thick_mode_lib_dir_test)
         with pytest.raises(TypeError, match=r"thick_mode_lib_dir expected str 
or None, got.*"):
-            thick_mode_lib_dir_test = {"thick_mode": True, 
"thick_mode_lib_dir": 1}
-            self.connection.extra = json.dumps(thick_mode_lib_dir_test)
             self.db_hook.get_conn()
 
     def test_type_checking_thick_mode_config_dir(self):
+        thick_mode_config_dir_test = {"thick_mode": True, 
"thick_mode_config_dir": 1}
+        self.connection.extra = json.dumps(thick_mode_config_dir_test)
         with pytest.raises(TypeError, match=r"thick_mode_config_dir expected 
str or None, got.*"):
-            thick_mode_config_dir_test = {"thick_mode": True, 
"thick_mode_config_dir": 1}
-            self.connection.extra = json.dumps(thick_mode_config_dir_test)
             self.db_hook.get_conn()
 
 

Reply via email to