This is an automated email from the ASF dual-hosted git repository.
jasonliu 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 5c7dcdc46ef Enable pt011 rule 0 (#55659)
5c7dcdc46ef is described below
commit 5c7dcdc46ef7397250f220b80d07d4225d6b31b8
Author: Xch1 <[email protected]>
AuthorDate: Thu Sep 18 10:58:29 2025 +0800
Enable pt011 rule 0 (#55659)
---
.../definitions/decorators/test_task_group.py | 20 ++++++++------------
task-sdk/tests/task_sdk/definitions/test_asset.py | 8 +++-----
.../task_sdk/definitions/test_asset_decorators.py | 7 ++-----
task-sdk/tests/task_sdk/definitions/test_dag.py | 8 ++++++--
task-sdk/tests/task_sdk/io/test_path.py | 2 +-
5 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/task-sdk/tests/task_sdk/definitions/decorators/test_task_group.py
b/task-sdk/tests/task_sdk/definitions/decorators/test_task_group.py
index 6cbf16a1e69..26e06cbfd6d 100644
--- a/task-sdk/tests/task_sdk/definitions/decorators/test_task_group.py
+++ b/task-sdk/tests/task_sdk/definitions/decorators/test_task_group.py
@@ -174,14 +174,12 @@ def test_expand_invalid_xcomarg_return_value():
tg.partial(a=1).expand(b=t()["values"])
- with pytest.raises(ValueError) as ctx:
+ with pytest.raises(
+ ValueError,
+ match=r"cannot map over XCom with custom key 'values' from
<Task\(_PythonDecoratedOperator\): t>",
+ ):
pipeline()
- assert (
- str(ctx.value)
- == "cannot map over XCom with custom key 'values' from
<Task(_PythonDecoratedOperator): t>"
- )
-
def test_expand_kwargs_no_wildcard():
@dag(schedule=None, start_date=pendulum.datetime(2022, 1, 1))
@@ -235,14 +233,12 @@ def test_expand_kwargs_invalid_xcomarg_return_value():
tg.partial(a=1).expand_kwargs(t()["values"])
- with pytest.raises(ValueError) as ctx:
+ with pytest.raises(
+ ValueError,
+ match=r"cannot map over XCom with custom key 'values' from
<Task\(_PythonDecoratedOperator\): t>",
+ ):
pipeline()
- assert (
- str(ctx.value)
- == "cannot map over XCom with custom key 'values' from
<Task(_PythonDecoratedOperator): t>"
- )
-
def test_override_dag_default_args():
@dag(
diff --git a/task-sdk/tests/task_sdk/definitions/test_asset.py
b/task-sdk/tests/task_sdk/definitions/test_asset.py
index fd9b6d24bcc..e9be2d297de 100644
--- a/task-sdk/tests/task_sdk/definitions/test_asset.py
+++ b/task-sdk/tests/task_sdk/definitions/test_asset.py
@@ -65,7 +65,7 @@ ASSET_MODULE_PATH = "airflow.sdk.definitions.asset"
def test_invalid_names(sql_conn_value, name, should_raise, monkeypatch):
monkeypatch.setattr("airflow.sdk.definitions.asset.SQL_ALCHEMY_CONN",
sql_conn_value)
if should_raise:
- with pytest.raises(ValueError):
+ with pytest.raises(ValueError, match="Asset name"):
Asset(name=name)
else:
Asset(name=name)
@@ -96,7 +96,7 @@ def test_invalid_names(sql_conn_value, name, should_raise,
monkeypatch):
def test_invalid_uris(sql_conn_value, uri, should_raise, monkeypatch):
monkeypatch.setattr("airflow.sdk.definitions.asset.SQL_ALCHEMY_CONN",
sql_conn_value)
if should_raise:
- with pytest.raises(ValueError):
+ with pytest.raises(ValueError, match="Asset"):
Asset(uri=uri)
else:
Asset(uri=uri)
@@ -386,10 +386,8 @@ def _mock_get_uri_normalizer_noop(normalized_scheme):
_mock_get_uri_normalizer_raising_error,
)
def test_sanitize_uri_raises_exception():
- with pytest.raises(ValueError) as e_info:
+ with pytest.raises(ValueError, match="Incorrect URI format"):
_sanitize_uri("postgres://localhost:5432/database.schema.table")
- assert isinstance(e_info.value, ValueError)
- assert str(e_info.value) == "Incorrect URI format"
@mock.patch("airflow.sdk.definitions.asset._get_uri_normalizer",
return_value=None)
diff --git a/task-sdk/tests/task_sdk/definitions/test_asset_decorators.py
b/task-sdk/tests/task_sdk/definitions/test_asset_decorators.py
index 3dfc0b44588..0b6b7e71c2b 100644
--- a/task-sdk/tests/task_sdk/definitions/test_asset_decorators.py
+++ b/task-sdk/tests/task_sdk/definitions/test_asset_decorators.py
@@ -115,20 +115,17 @@ class TestAssetDecorator:
def asset_func():
pass
- with pytest.raises(ValueError) as err:
+ with pytest.raises(ValueError, match="nested function not supported"):
root_func()
- assert err.value.args[0] == "nested function not supported"
-
@pytest.mark.parametrize("func_fixer", ("self", "context"), indirect=True)
def test_with_invalid_asset_name(self, func_fixer):
@func_fixer
def example_asset_func():
pass
- with pytest.raises(ValueError) as err:
+ with pytest.raises(ValueError, match=f"prohibited name for asset:
{func_fixer.fixed_name}"):
asset(schedule=None)(example_asset_func)
- assert err.value.args[0] == f"prohibited name for asset:
{func_fixer.fixed_name}"
def test_with_star(self, func_fixer):
@func_fixer
diff --git a/task-sdk/tests/task_sdk/definitions/test_dag.py
b/task-sdk/tests/task_sdk/definitions/test_dag.py
index ed8db6b0aac..f61475adfa9 100644
--- a/task-sdk/tests/task_sdk/definitions/test_dag.py
+++ b/task-sdk/tests/task_sdk/definitions/test_dag.py
@@ -212,7 +212,11 @@ class TestDag:
"""
params = {"param1": Param(type="string")}
- with pytest.raises(ValueError):
+ with pytest.raises(
+ ValueError,
+ match="Dag 'my-dag' is not allowed to define a Schedule, "
+ "as there are required params without default values, or the
default values are not valid.",
+ ):
DAG("my-dag", schedule=timedelta(days=1), start_date=DEFAULT_DATE,
params=params)
def test_roots(self):
@@ -419,7 +423,7 @@ def test__tags_length(tags: list[str], should_pass: bool):
if should_pass:
DAG("test-dag", schedule=None, tags=tags)
else:
- with pytest.raises(ValueError):
+ with pytest.raises(ValueError, match="tag cannot be longer than 100
characters"):
DAG("test-dag", schedule=None, tags=tags)
diff --git a/task-sdk/tests/task_sdk/io/test_path.py
b/task-sdk/tests/task_sdk/io/test_path.py
index a85517a1ad4..78c75cebddf 100644
--- a/task-sdk/tests/task_sdk/io/test_path.py
+++ b/task-sdk/tests/task_sdk/io/test_path.py
@@ -254,7 +254,7 @@ class TestLocalPath:
o2 = ObjectStoragePath(f"file://{tmp_path.as_posix()}")
o3 = ObjectStoragePath(f"file:///{uuid.uuid4()}")
assert o1.relative_to(o2) == o1
- with pytest.raises(ValueError):
+ with pytest.raises(ValueError, match="is not in the subpath of"):
o1.relative_to(o3)
def test_asset(self):