You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2025/10/13 20:29:44 UTC

(airflow) branch main updated: Enable PT011 rule to prvoider tests (#56495)

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

commit afa7dbe6941b8b91f4dd4a92375213747894f988
Author: Xch1 <34...@users.noreply.github.com>
AuthorDate: Tue Oct 14 04:29:37 2025 +0800

    Enable PT011 rule to prvoider tests (#56495)
    
    * modify hooks/test_sql
    
    Signed-off-by: Xch1 <qc...@gmail.com>
    
    * modify hooks/test_dbapi
    
    Signed-off-by: Xch1 <qc...@gmail.com>
    
    * modify triggers/test_msg_queue
    
    Signed-off-by: Xch1 <qc...@gmail.com>
    
    * modify assets/test_file
    
    Signed-off-by: Xch1 <qc...@gmail.com>
    
    * modify openlineage/test_check
    
    Signed-off-by: Xch1 <qc...@gmail.com>
    
    ---------
    
    Signed-off-by: Xch1 <qc...@gmail.com>
---
 .../unit/common/compat/openlineage/test_check.py      | 19 ++++---------------
 .../io/tests/unit/common/io/assets/test_file.py       |  2 +-
 .../unit/common/messaging/triggers/test_msg_queue.py  |  2 +-
 .../sql/tests/unit/common/sql/hooks/test_dbapi.py     |  3 +--
 .../sql/tests/unit/common/sql/hooks/test_sql.py       |  3 +--
 5 files changed, 8 insertions(+), 21 deletions(-)

diff --git a/providers/common/compat/tests/unit/common/compat/openlineage/test_check.py b/providers/common/compat/tests/unit/common/compat/openlineage/test_check.py
index 43317509e5a..77f2a4a2eba 100644
--- a/providers/common/compat/tests/unit/common/compat/openlineage/test_check.py
+++ b/providers/common/compat/tests/unit/common/compat/openlineage/test_check.py
@@ -27,6 +27,8 @@ import pytest
 from airflow.exceptions import AirflowOptionalProviderFeatureException
 from airflow.providers.common.compat.openlineage.check import require_openlineage_version
 
+REQUIRE_OPENLINEAGE_VERSION = r"`require_openlineage_version` decorator must be used with at least one argument.*@require_openlineage_version\(provider_min_version=\"1\.0\.0\"\)"
+
 
 def _mock_version(package):
     if package == "apache-airflow-providers-openlineage":
@@ -52,29 +54,16 @@ def test_decorator_without_arguments():
 
 
 def test_decorator_without_arguments_with_parentheses():
-    with pytest.raises(ValueError) as excinfo:
+    with pytest.raises(ValueError, match=REQUIRE_OPENLINEAGE_VERSION):
 
         @require_openlineage_version()
         def dummy():
             return "result"
 
-    expected_error = (
-        "`require_openlineage_version` decorator must be used with at least one argument: "
-        "'provider_min_version' or 'client_min_version', "
-        'e.g., @require_openlineage_version(provider_min_version="1.0.0")'
-    )
-    assert str(excinfo.value) == expected_error
-
 
 def test_no_arguments_provided():
-    with pytest.raises(ValueError) as excinfo:
+    with pytest.raises(ValueError, match=REQUIRE_OPENLINEAGE_VERSION):
         require_openlineage_version()
-    expected_error = (
-        "`require_openlineage_version` decorator must be used with at least one argument: "
-        "'provider_min_version' or 'client_min_version', "
-        'e.g., @require_openlineage_version(provider_min_version="1.0.0")'
-    )
-    assert str(excinfo.value) == expected_error
 
 
 @pytest.mark.parametrize("provider_min_version", ("1.0.0", "0.9", "0", "0.9.9", "1.0.0.dev0", "1.0.0rc1"))
diff --git a/providers/common/io/tests/unit/common/io/assets/test_file.py b/providers/common/io/tests/unit/common/io/assets/test_file.py
index 49b1b0ffa76..fd1ea03a740 100644
--- a/providers/common/io/tests/unit/common/io/assets/test_file.py
+++ b/providers/common/io/tests/unit/common/io/assets/test_file.py
@@ -44,7 +44,7 @@ def test_sanitize_uri_valid(uri, expected):
 
 @pytest.mark.parametrize("uri", ("file://",))
 def test_sanitize_uri_invalid(uri):
-    with pytest.raises(ValueError):
+    with pytest.raises(ValueError, match="URI format file:// must contain a non-empty path."):
         sanitize_uri(urlsplit(uri))
 
 
diff --git a/providers/common/messaging/tests/unit/common/messaging/triggers/test_msg_queue.py b/providers/common/messaging/tests/unit/common/messaging/triggers/test_msg_queue.py
index 4ee43f027d2..b81bd6469d4 100644
--- a/providers/common/messaging/tests/unit/common/messaging/triggers/test_msg_queue.py
+++ b/providers/common/messaging/tests/unit/common/messaging/triggers/test_msg_queue.py
@@ -135,7 +135,7 @@ class TestMessageQueueTrigger:
         with mock.patch(MESSAGE_QUEUE_PROVIDERS_PATH, [provider1, provider2]):
             trigger = MessageQueueTrigger(queue=UNSUPPORTED_QUEUE)
 
-            with pytest.raises(ValueError):
+            with pytest.raises(ValueError, match=UNSUPPORTED_QUEUE):
                 _ = trigger.trigger
 
     def test_trigger_kwargs_passed_correctly(self):
diff --git a/providers/common/sql/tests/unit/common/sql/hooks/test_dbapi.py b/providers/common/sql/tests/unit/common/sql/hooks/test_dbapi.py
index b3fb7a476f0..62e5bf78336 100644
--- a/providers/common/sql/tests/unit/common/sql/hooks/test_dbapi.py
+++ b/providers/common/sql/tests/unit/common/sql/hooks/test_dbapi.py
@@ -577,9 +577,8 @@ class TestDbApiHook:
         assert result == [obj, obj]
 
     def test_run_no_queries(self):
-        with pytest.raises(ValueError) as err:
+        with pytest.raises(ValueError, match="List of SQL statements is empty"):
             self.db_hook.run(sql=[])
-        assert err.value.args[0] == "List of SQL statements is empty"
 
     def test_run_and_log_db_messages(self):
         statement = "SQL"
diff --git a/providers/common/sql/tests/unit/common/sql/hooks/test_sql.py b/providers/common/sql/tests/unit/common/sql/hooks/test_sql.py
index b9003103244..dee8ac692b2 100644
--- a/providers/common/sql/tests/unit/common/sql/hooks/test_sql.py
+++ b/providers/common/sql/tests/unit/common/sql/hooks/test_sql.py
@@ -239,9 +239,8 @@ class TestDbApiHook:
     )
     def test_no_query(self, empty_statement):
         dbapi_hook = mock_db_hook(DbApiHook)
-        with pytest.raises(ValueError) as err:
+        with pytest.raises(ValueError, match="List of SQL statements is empty"):
             dbapi_hook.run(sql=empty_statement)
-        assert err.value.args[0] == "List of SQL statements is empty"
 
     @pytest.mark.db_test
     def test_placeholder_config_from_extra(self):