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 b3f90be0353 Enable PT011 rule to prvoider tests (#56698)
b3f90be0353 is described below

commit b3f90be03538fda6710aba051c3816ba0a10d05d
Author: Xch1 <[email protected]>
AuthorDate: Thu Oct 16 17:07:54 2025 +0800

    Enable PT011 rule to prvoider tests (#56698)
    
    * modify test_ecs
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_s3
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_redshift_data
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_eventbridge
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_batch_waiters
    
    Signed-off-by: Xch1 <[email protected]>
    
    ---------
    
    Signed-off-by: Xch1 <[email protected]>
---
 .../unit/amazon/aws/hooks/test_batch_waiters.py    |  3 +-
 .../unit/amazon/aws/hooks/test_eventbridge.py      |  2 +-
 .../unit/amazon/aws/hooks/test_redshift_data.py    |  9 +++--
 .../amazon/tests/unit/amazon/aws/hooks/test_s3.py  | 15 +++++----
 .../tests/unit/amazon/aws/operators/test_ecs.py    | 39 ++++++++++------------
 5 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/providers/amazon/tests/unit/amazon/aws/hooks/test_batch_waiters.py 
b/providers/amazon/tests/unit/amazon/aws/hooks/test_batch_waiters.py
index e7ae40d7a3a..014699c1491 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_batch_waiters.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_batch_waiters.py
@@ -106,9 +106,8 @@ class TestBatchWaiters:
         assert waiters == ["JobComplete", "JobExists", "JobRunning"]
 
         # test errors when requesting a waiter with the wrong name
-        with pytest.raises(ValueError) as ctx:
+        with pytest.raises(ValueError, match="Waiter does not exist: 
JobExist"):
             model.get_waiter("JobExist")
-        assert "Waiter does not exist: JobExist" in str(ctx.value)
 
         # test some default waiter properties
         waiter = model.get_waiter("JobExists")
diff --git a/providers/amazon/tests/unit/amazon/aws/hooks/test_eventbridge.py 
b/providers/amazon/tests/unit/amazon/aws/hooks/test_eventbridge.py
index 62fbb5ef55e..e1eac5f07fb 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_eventbridge.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_eventbridge.py
@@ -39,7 +39,7 @@ class TestEventBridgeHook:
 
     def test_put_rule_with_bad_json_fails(self):
         hook = EventBridgeHook(aws_conn_id="aws_default")
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match="`event_pattern` must be a valid 
JSON string."):
             hook.put_rule(
                 name="test",
                 event_pattern="invalid json",
diff --git a/providers/amazon/tests/unit/amazon/aws/hooks/test_redshift_data.py 
b/providers/amazon/tests/unit/amazon/aws/hooks/test_redshift_data.py
index 96e33516d5d..8cec2302b6d 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_redshift_data.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_redshift_data.py
@@ -32,6 +32,9 @@ from airflow.providers.amazon.aws.hooks.redshift_data import (
 SQL = "sql"
 DATABASE = "database"
 STATEMENT_ID = "statement_id"
+EXACTLY_ONE_REQUIRED_ERROR_MSG = (
+    "Exactly one of cluster_identifier, workgroup_name, or session_id must be 
provided"
+)
 
 
 class TestRedshiftDataHook:
@@ -81,7 +84,7 @@ class TestRedshiftDataHook:
         cluster_identifier = "cluster_identifier"
         workgroup_name = "workgroup_name"
         hook = RedshiftDataHook()
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=EXACTLY_ONE_REQUIRED_ERROR_MSG):
             hook.execute_query(
                 database=DATABASE,
                 cluster_identifier=cluster_identifier,
@@ -109,7 +112,7 @@ class TestRedshiftDataHook:
         cluster_identifier = "cluster_identifier"
         workgroup_name = "workgroup_name"
         hook = RedshiftDataHook()
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=EXACTLY_ONE_REQUIRED_ERROR_MSG):
             hook.execute_query(
                 database=DATABASE,
                 cluster_identifier=cluster_identifier,
@@ -125,7 +128,7 @@ class TestRedshiftDataHook:
         cluster_identifier = "cluster_identifier"
         workgroup_name = "workgroup_name"
         hook = RedshiftDataHook()
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=EXACTLY_ONE_REQUIRED_ERROR_MSG):
             hook.execute_query(
                 database=DATABASE,
                 cluster_identifier=cluster_identifier,
diff --git a/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py 
b/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py
index d74bc3d6797..b275d0b0f55 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py
@@ -55,6 +55,8 @@ try:
 except ImportError:
     BASEHOOK_PATCH_PATH = "airflow.hooks.base.BaseHook"
 
+KEY_VALUE_SPECIFICATION_ERROR = "Key and Value must be specified as a pair. 
Only one of the two had a value"
+
 
 @pytest.fixture
 def mocked_s3_res():
@@ -1413,9 +1415,8 @@ class TestAwsS3Hook:
         test_bucket_name_with_key = 
fake_s3_hook.test_function_with_key("s3://foo/bar.csv")
         assert test_bucket_name_with_key == ("foo", "bar.csv")
 
-        with pytest.raises(ValueError) as ctx:
+        with pytest.raises(ValueError, match="Missing key parameter!"):
             fake_s3_hook.test_function_with_test_key("s3://foo/bar.csv")
-        assert isinstance(ctx.value, ValueError)
 
     @mock.patch("airflow.providers.amazon.aws.hooks.s3.NamedTemporaryFile")
     def test_download_file(self, mock_temp_file, tmp_path):
@@ -1601,7 +1602,7 @@ class TestAwsS3Hook:
         hook = S3Hook(extra_args={"unknown_s3_args": "value"})
         path = tmp_path / "testfile"
         path.write_text("Content")
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match="Invalid extra_args key 
'unknown_s3_args'"):
             hook.load_file_obj(path.open("rb"), "my_key", s3_bucket, 
acl_policy="public-read")
 
     def test_should_pass_extra_args(self, s3_bucket, tmp_path):
@@ -1726,7 +1727,7 @@ class TestAwsS3Hook:
 
         hook.create_bucket(bucket_name="new_bucket")
         key = "Color"
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=KEY_VALUE_SPECIFICATION_ERROR):
             hook.put_bucket_tagging(bucket_name="new_bucket", key=key)
 
     @mock_aws
@@ -1734,7 +1735,7 @@ class TestAwsS3Hook:
         hook = S3Hook()
         hook.create_bucket(bucket_name="new_bucket")
         value = "Color"
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=KEY_VALUE_SPECIFICATION_ERROR):
             hook.put_bucket_tagging(bucket_name="new_bucket", value=value)
 
     @mock_aws
@@ -1743,7 +1744,7 @@ class TestAwsS3Hook:
         hook.create_bucket(bucket_name="new_bucket")
         tag_set = [{"Key": "Color", "Value": "Green"}]
         key = "Color"
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=KEY_VALUE_SPECIFICATION_ERROR):
             hook.put_bucket_tagging(bucket_name="new_bucket", key=key, 
tag_set=tag_set)
 
     @mock_aws
@@ -1752,7 +1753,7 @@ class TestAwsS3Hook:
         hook.create_bucket(bucket_name="new_bucket")
         tag_set = [{"Key": "Color", "Value": "Green"}]
         value = "Green"
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match=KEY_VALUE_SPECIFICATION_ERROR):
             hook.put_bucket_tagging(bucket_name="new_bucket", value=value, 
tag_set=tag_set)
 
     @mock_aws
diff --git a/providers/amazon/tests/unit/amazon/aws/operators/test_ecs.py 
b/providers/amazon/tests/unit/amazon/aws/operators/test_ecs.py
index 23d3fdc9282..fa1cc20a817 100644
--- a/providers/amazon/tests/unit/amazon/aws/operators/test_ecs.py
+++ b/providers/amazon/tests/unit/amazon/aws/operators/test_ecs.py
@@ -469,12 +469,12 @@ class TestEcsRunTaskOperator(EcsBaseTestCase):
             "tasks": [{"containers": [{"name": "foo", "lastStatus": "STOPPED", 
"exitCode": 1}]}]
         }
 
-        with pytest.raises(Exception) as ctx:
+        with pytest.raises(
+            Exception,
+            match="This task is not in success state - last 10 logs from 
Cloudwatch:\n1\n2\n3\n4\n5",
+        ):
             self.ecs._check_success_task()
 
-        assert str(ctx.value) == (
-            "This task is not in success state - last 10 logs from 
Cloudwatch:\n1\n2\n3\n4\n5"
-        )
         client_mock.describe_tasks.assert_called_once_with(cluster="c", 
tasks=["arn"])
 
     @mock.patch.object(EcsBaseOperator, "client")
@@ -488,10 +488,11 @@ class TestEcsRunTaskOperator(EcsBaseTestCase):
             "tasks": [{"containers": [{"name": "foo", "lastStatus": "STOPPED", 
"exitCode": 1}]}]
         }
 
-        with pytest.raises(Exception) as ctx:
+        with pytest.raises(
+            Exception, match="This task is not in success state - last 10 logs 
from Cloudwatch:\n"
+        ):
             self.ecs._check_success_task()
 
-        assert str(ctx.value) == "This task is not in success state - last 10 
logs from Cloudwatch:\n"
         client_mock.describe_tasks.assert_called_once_with(cluster="c", 
tasks=["arn"])
 
     @mock.patch.object(EcsBaseOperator, "client")
@@ -502,13 +503,12 @@ class TestEcsRunTaskOperator(EcsBaseTestCase):
             "tasks": [{"containers": [{"name": "foo", "lastStatus": "STOPPED", 
"exitCode": 1}]}]
         }
 
-        with pytest.raises(Exception) as ctx:
+        with pytest.raises(
+            Exception,
+            match=r"This task is not in success state .*'name': 
'foo'.*'lastStatus': 'STOPPED'.*'exitCode': 1",
+        ):
             self.ecs._check_success_task()
 
-        assert "This task is not in success state " in str(ctx.value)
-        assert "'name': 'foo'" in str(ctx.value)
-        assert "'lastStatus': 'STOPPED'" in str(ctx.value)
-        assert "'exitCode': 1" in str(ctx.value)
         client_mock.describe_tasks.assert_called_once_with(cluster="c", 
tasks=["arn"])
 
     @mock.patch.object(EcsBaseOperator, "client")
@@ -520,14 +520,11 @@ class TestEcsRunTaskOperator(EcsBaseTestCase):
             "tasks": [{"containers": [{"name": "foo", "lastStatus": 
"STOPPED"}]}]
         }
 
-        with pytest.raises(Exception) as ctx:
+        with pytest.raises(
+            Exception, match=r"This task is not in success state .*'name': 
'foo'.*'lastStatus': 'STOPPED'"
+        ):
             self.ecs._check_success_task()
 
-        print(str(ctx.value))
-        assert "This task is not in success state " in str(ctx.value)
-        assert "'name': 'foo'" in str(ctx.value)
-        assert "'lastStatus': 'STOPPED'" in str(ctx.value)
-        assert "exitCode" not in str(ctx.value)
         client_mock.describe_tasks.assert_called_once_with(cluster="c", 
tasks=["arn"])
 
     @mock.patch.object(EcsBaseOperator, "client")
@@ -536,12 +533,10 @@ class TestEcsRunTaskOperator(EcsBaseTestCase):
         client_mock.describe_tasks.return_value = {
             "tasks": [{"containers": [{"name": "container-name", "lastStatus": 
"PENDING"}]}]
         }
-        with pytest.raises(Exception) as ctx:
+        with pytest.raises(
+            Exception, match=r"This task is still pending .*'name': 
'container-name'.*'lastStatus': 'PENDING'"
+        ):
             self.ecs._check_success_task()
-        # Ordering of str(dict) is not guaranteed.
-        assert "This task is still pending " in str(ctx.value)
-        assert "'name': 'container-name'" in str(ctx.value)
-        assert "'lastStatus': 'PENDING'" in str(ctx.value)
         client_mock.describe_tasks.assert_called_once_with(cluster="c", 
tasks=["arn"])
 
     @mock.patch.object(EcsBaseOperator, "client")

Reply via email to