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 84c482dcde2 Enable PT011 rule to airflow-core tests (#57399)
84c482dcde2 is described below

commit 84c482dcde2615a3aa497417a17a9f258bdc47a7
Author: Xch1 <[email protected]>
AuthorDate: Tue Oct 28 13:33:24 2025 +0800

    Enable PT011 rule to airflow-core tests (#57399)
    
    * modify test_dag_serialization
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_xcom_arg
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_taskinstance
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_deadline
    
    Signed-off-by: Xch1 <[email protected]>
    
    * modify test_dagrun
    
    Signed-off-by: Xch1 <[email protected]>
    
    ---------
    
    Signed-off-by: Xch1 <[email protected]>
---
 airflow-core/tests/unit/models/test_dagrun.py                |  2 +-
 airflow-core/tests/unit/models/test_deadline.py              | 12 ++++++------
 airflow-core/tests/unit/models/test_taskinstance.py          |  6 ++++--
 airflow-core/tests/unit/models/test_xcom_arg.py              |  3 +--
 .../tests/unit/serialization/test_dag_serialization.py       |  5 ++---
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/airflow-core/tests/unit/models/test_dagrun.py 
b/airflow-core/tests/unit/models/test_dagrun.py
index af80e153bf0..df3bd4e354a 100644
--- a/airflow-core/tests/unit/models/test_dagrun.py
+++ b/airflow-core/tests/unit/models/test_dagrun.py
@@ -2805,7 +2805,7 @@ def test_dag_run_id_config(session, dag_maker, pattern, 
run_id, result):
         if result:
             dag_maker.create_dagrun(run_id=run_id, run_type=run_type)
         else:
-            with pytest.raises(ValueError):
+            with pytest.raises(ValueError, match=r"The run_id provided '.+' 
does not match regex pattern"):
                 dag_maker.create_dagrun(run_id=run_id, run_type=run_type)
 
 
diff --git a/airflow-core/tests/unit/models/test_deadline.py 
b/airflow-core/tests/unit/models/test_deadline.py
index 05229488fc3..4ce17772cde 100644
--- a/airflow-core/tests/unit/models/test_deadline.py
+++ b/airflow-core/tests/unit/models/test_deadline.py
@@ -16,6 +16,7 @@
 # under the License.
 from __future__ import annotations
 
+import re
 from datetime import datetime, timedelta
 from unittest import mock
 
@@ -551,13 +552,12 @@ class TestDeadlineReference:
     def test_deadline_missing_required_kwargs(self, reference, session):
         """Test that deadlines raise appropriate errors for missing required 
parameters."""
         if reference.required_kwargs:
-            with pytest.raises(ValueError) as raised_exception:
+            with pytest.raises(
+                ValueError, match=re.escape(f"{reference.__class__.__name__} 
is missing required parameters:")
+            ) as raised_exception:
                 reference.evaluate_with(session=session, **self.DEFAULT_ARGS)
-            expected_substrings = {
-                f"{reference.__class__.__name__} is missing required 
parameters: ",
-                *reference.required_kwargs,
-            }
-            assert all(substring in str(raised_exception.value) for substring 
in expected_substrings)
+
+            assert all(substring in str(raised_exception.value) for substring 
in reference.required_kwargs)
         else:
             # Let the lack of an exception here effectively assert that no 
exception is raised.
             reference.evaluate_with(session=session, **self.DEFAULT_ARGS)
diff --git a/airflow-core/tests/unit/models/test_taskinstance.py 
b/airflow-core/tests/unit/models/test_taskinstance.py
index fccac898d31..d2ddd32848b 100644
--- a/airflow-core/tests/unit/models/test_taskinstance.py
+++ b/airflow-core/tests/unit/models/test_taskinstance.py
@@ -221,7 +221,7 @@ class TestTaskInstance:
         op.dag = dag
 
         # no reassignment
-        with pytest.raises(ValueError):
+        with pytest.raises(ValueError, match="can not be changed"):
             op.dag = dag2
 
         # but assigning the same dag is ok
@@ -243,7 +243,9 @@ class TestTaskInstance:
         assert [i.has_dag() for i in [op1, op2, op3, op4]] == [False, False, 
True, True]
 
         # can't combine operators with no dags
-        with pytest.raises(ValueError):
+        with pytest.raises(
+            ValueError, match="Tried to create relationships between tasks 
that don't have Dags yet"
+        ):
             op1.set_downstream(op2)
 
         # op2 should infer dag from op1
diff --git a/airflow-core/tests/unit/models/test_xcom_arg.py 
b/airflow-core/tests/unit/models/test_xcom_arg.py
index e7b37cc6ed7..7fe45d2a584 100644
--- a/airflow-core/tests/unit/models/test_xcom_arg.py
+++ b/airflow-core/tests/unit/models/test_xcom_arg.py
@@ -123,9 +123,8 @@ class TestXComArgBuild:
     def test_xcom_key_getitem_not_str(self, dag_maker):
         python_op = build_python_op(dag_maker)
         actual = XComArg(python_op)
-        with pytest.raises(ValueError) as ctx:
+        with pytest.raises(ValueError, match="XComArg only supports str 
lookup, received int"):
             actual[1]
-        assert str(ctx.value) == "XComArg only supports str lookup, received 
int"
 
     def test_xcom_key_getitem(self, dag_maker):
         python_op = build_python_op(dag_maker)
diff --git a/airflow-core/tests/unit/serialization/test_dag_serialization.py 
b/airflow-core/tests/unit/serialization/test_dag_serialization.py
index 40864f18ee7..03e205f2c98 100644
--- a/airflow-core/tests/unit/serialization/test_dag_serialization.py
+++ b/airflow-core/tests/unit/serialization/test_dag_serialization.py
@@ -1064,8 +1064,6 @@ class TestStringifiedDAGs:
             },
         }
         SerializedDAG.validate_schema(serialized)
-        with pytest.raises(ValueError) as ctx:
-            SerializedDAG.from_dict(serialized)
         message = (
             "Timetable class "
             "'tests_common.test_utils.timetables.CustomSerializationTimetable' 
"
@@ -1073,7 +1071,8 @@ class TestStringifiedDAGs:
             "you have a top level database access that disrupted the session. "
             "Please check the airflow best practices documentation."
         )
-        assert str(ctx.value) == message
+        with pytest.raises(ValueError, match=message):
+            SerializedDAG.from_dict(serialized)
 
     @pytest.mark.parametrize(
         "val, expected",

Reply via email to