You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "KoviAnusha (via GitHub)" <gi...@apache.org> on 2025/11/04 23:19:49 UTC

[PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

KoviAnusha opened a new pull request, #57833:
URL: https://github.com/apache/airflow/pull/57833

   Issue: Enable Even More PyDocStyle Checks https://github.com/apache/airflow/issues/40567
   @ferruzzi
   
   This PR is for enable PT006 rule:
   PT011: all instances of @pytest.mark.parametrize names should be a tuple
   https://docs.astral.sh/ruff/rules/pytest-parametrize-names-wrong-type/
   There are a lot of file changes needed.
   So, I separate to many PR, which contain about 9 file changes for easy review.
   
   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "xchwan (via GitHub)" <gi...@apache.org>.
xchwan commented on code in PR #57833:
URL: https://github.com/apache/airflow/pull/57833#discussion_r2495941568


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -342,7 +342,7 @@ def test_json_exc(structlog_config, get_logger, monkeypatch):
 
 
 @pytest.mark.parametrize(
-    ("levels",),
+    "levels",

Review Comment:
   ```python
   @staticmethod
       def _parse_parametrize_args(
           argnames: str | Sequence[str],
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           *args,
           **kwargs,
       ) -> tuple[Sequence[str], bool]:
           if isinstance(argnames, str):
               argnames = [x.strip() for x in argnames.split(",") if x.strip()]
               force_tuple = len(argnames) == 1
           else:
               force_tuple = False
           return argnames, force_tuple
   
       @staticmethod
       def _parse_parametrize_parameters(
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           force_tuple: bool,
       ) -> list[ParameterSet]:
           return [
               ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues
           ]
   
       @classmethod
       def _for_parametrize(
           cls,
           argnames: str | Sequence[str],
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           func,
           config: Config,
           nodeid: str,
       ) -> tuple[Sequence[str], list[ParameterSet]]:
           argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues)
           parameters = cls._parse_parametrize_parameters(argvalues, force_tuple)
           del argvalues
   
           if parameters:
               # Check all parameter sets have the correct number of values.
               for param in parameters:
                   if len(param.values) != len(argnames):
                       msg = (
                           '{nodeid}: in "parametrize" the number of names ({names_len}):\n'
                           "  {names}\n"
                           "must be equal to the number of values ({values_len}):\n"
                           "  {values}"
                       )
                       fail(
                           msg.format(
                               nodeid=nodeid,
                               values=param.values,
                               names=argnames,
                               names_len=len(argnames),
                               values_len=len(param.values),
                           ),
                           pytrace=False,
                       )
           else:
               # Empty parameter set (likely computed at runtime): create a single
               # parameter set with NOTSET values, with the "empty parameter set" mark applied to it.
               mark = get_empty_parameterset_mark(config, argnames, func)
               parameters.append(
                   ParameterSet(
                       values=(NOTSET,) * len(argnames), marks=[mark], id="NOTSET"
                   )
               )
           return argnames, parameters
   ```
   The error is happened in ```len(param.values) != len(argnames)``` where object() no len()
   _parse_parametrize_args shows:
   write ("contain",) force_tuple = false
   write "contain", force_tuple = true
   _parse_parametrize_parameters show:
   force_tuple will decide whether argvalues
   ```python
    @classmethod
       def extract_from(
           cls,
           parameterset: ParameterSet | Sequence[object] | object,
           force_tuple: bool = False,
       ) -> ParameterSet:
           """Extract from an object or objects.
   
           :param parameterset:
               A legacy style parameterset that may or may not be a tuple,
               and may or may not be wrapped into a mess of mark objects.
   
           :param force_tuple:
               Enforce tuple wrapping so single argument tuple values
               don't get decomposed and break tests.
           """
           if isinstance(parameterset, cls):
               return parameterset
           if force_tuple:
               return cls.param(parameterset)
           else:
               # TODO: Refactor to fix this type-ignore. Currently the following
               # passes type-checking but crashes:
               #
               #   @pytest.mark.parametrize(('x', 'y'), [1, 2])
               #   def test_foo(x, y): pass
               return cls(parameterset, marks=[], id=None)  # type: ignore[arg-type]
   ```
   Here, "contain" force_tuple is true, param.value becomes (object(),)=>len should be 1.
   ("contain", ) force_tuple is false, so I think it go else and param.values is object(), and len(object())->failed.
   
   and what "pytest.param" do is the same as force_tuple = true do.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "xchwan (via GitHub)" <gi...@apache.org>.
xchwan commented on code in PR #57833:
URL: https://github.com/apache/airflow/pull/57833#discussion_r2495941568


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -342,7 +342,7 @@ def test_json_exc(structlog_config, get_logger, monkeypatch):
 
 
 @pytest.mark.parametrize(
-    ("levels",),
+    "levels",

Review Comment:
   ```python
   @staticmethod
       def _parse_parametrize_args(
           argnames: str | Sequence[str],
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           *args,
           **kwargs,
       ) -> tuple[Sequence[str], bool]:
           if isinstance(argnames, str):
               argnames = [x.strip() for x in argnames.split(",") if x.strip()]
               force_tuple = len(argnames) == 1
           else:
               force_tuple = False
           return argnames, force_tuple
   
       @staticmethod
       def _parse_parametrize_parameters(
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           force_tuple: bool,
       ) -> list[ParameterSet]:
           return [
               ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues
           ]
   
       @classmethod
       def _for_parametrize(
           cls,
           argnames: str | Sequence[str],
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           func,
           config: Config,
           nodeid: str,
       ) -> tuple[Sequence[str], list[ParameterSet]]:
           argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues)
           parameters = cls._parse_parametrize_parameters(argvalues, force_tuple)
           del argvalues
   
           if parameters:
               # Check all parameter sets have the correct number of values.
               for param in parameters:
                   if len(param.values) != len(argnames):
                       msg = (
                           '{nodeid}: in "parametrize" the number of names ({names_len}):\n'
                           "  {names}\n"
                           "must be equal to the number of values ({values_len}):\n"
                           "  {values}"
                       )
                       fail(
                           msg.format(
                               nodeid=nodeid,
                               values=param.values,
                               names=argnames,
                               names_len=len(argnames),
                               values_len=len(param.values),
                           ),
                           pytrace=False,
                       )
           else:
               # Empty parameter set (likely computed at runtime): create a single
               # parameter set with NOTSET values, with the "empty parameter set" mark applied to it.
               mark = get_empty_parameterset_mark(config, argnames, func)
               parameters.append(
                   ParameterSet(
                       values=(NOTSET,) * len(argnames), marks=[mark], id="NOTSET"
                   )
               )
           return argnames, parameters
   ```
   The error is happened in ```len(param.values) != len(argnames)``` where object() no len()
   _parse_parametrize_args shows:
   write ("contain",) force_tuple = false
   write "contain", force_tuple = true
   _parse_parametrize_parameters show:
   force_tuple will decide whether argvalues
   ```python
    @classmethod
       def extract_from(
           cls,
           parameterset: ParameterSet | Sequence[object] | object,
           force_tuple: bool = False,
       ) -> ParameterSet:
           """Extract from an object or objects.
   
           :param parameterset:
               A legacy style parameterset that may or may not be a tuple,
               and may or may not be wrapped into a mess of mark objects.
   
           :param force_tuple:
               Enforce tuple wrapping so single argument tuple values
               don't get decomposed and break tests.
           """
           if isinstance(parameterset, cls):
               return parameterset
           if force_tuple:
               return cls.param(parameterset)
           else:
               # TODO: Refactor to fix this type-ignore. Currently the following
               # passes type-checking but crashes:
               #
               #   @pytest.mark.parametrize(('x', 'y'), [1, 2])
               #   def test_foo(x, y): pass
               return cls(parameterset, marks=[], id=None)  # type: ignore[arg-type]
   ```
   Here, "contain" force_tuple is true, param.value becomes (object(),)=>len should be 1.
   ("contain", ) force_tuple is false, so I think it go else and param.values is object(), and len(object())->failed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "xchwan (via GitHub)" <gi...@apache.org>.
xchwan commented on code in PR #57833:
URL: https://github.com/apache/airflow/pull/57833#discussion_r2495941568


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -342,7 +342,7 @@ def test_json_exc(structlog_config, get_logger, monkeypatch):
 
 
 @pytest.mark.parametrize(
-    ("levels",),
+    "levels",

Review Comment:
   ```python
   @staticmethod
       def _parse_parametrize_args(
           argnames: str | Sequence[str],
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           *args,
           **kwargs,
       ) -> tuple[Sequence[str], bool]:
           if isinstance(argnames, str):
               argnames = [x.strip() for x in argnames.split(",") if x.strip()]
               force_tuple = len(argnames) == 1
           else:
               force_tuple = False
           return argnames, force_tuple
   
       @staticmethod
       def _parse_parametrize_parameters(
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           force_tuple: bool,
       ) -> list[ParameterSet]:
           return [
               ParameterSet.extract_from(x, force_tuple=force_tuple) for x in argvalues
           ]
   
       @classmethod
       def _for_parametrize(
           cls,
           argnames: str | Sequence[str],
           argvalues: Iterable[ParameterSet | Sequence[object] | object],
           func,
           config: Config,
           nodeid: str,
       ) -> tuple[Sequence[str], list[ParameterSet]]:
           argnames, force_tuple = cls._parse_parametrize_args(argnames, argvalues)
           parameters = cls._parse_parametrize_parameters(argvalues, force_tuple)
           del argvalues
   
           if parameters:
               # Check all parameter sets have the correct number of values.
               for param in parameters:
                   if len(param.values) != len(argnames):
                       msg = (
                           '{nodeid}: in "parametrize" the number of names ({names_len}):\n'
                           "  {names}\n"
                           "must be equal to the number of values ({values_len}):\n"
                           "  {values}"
                       )
                       fail(
                           msg.format(
                               nodeid=nodeid,
                               values=param.values,
                               names=argnames,
                               names_len=len(argnames),
                               values_len=len(param.values),
                           ),
                           pytrace=False,
                       )
           else:
               # Empty parameter set (likely computed at runtime): create a single
               # parameter set with NOTSET values, with the "empty parameter set" mark applied to it.
               mark = get_empty_parameterset_mark(config, argnames, func)
               parameters.append(
                   ParameterSet(
                       values=(NOTSET,) * len(argnames), marks=[mark], id="NOTSET"
                   )
               )
           return argnames, parameters
   ```
   The error is happened in ```len(param.values) != len(argnames)``` where object() no len()
   _parse_parametrize_args shows:
   write ("contain",) force_tuple = false
   write "contain", force_tuple = true
   _parse_parametrize_parameters show:
   force_tuple will decide whether argvalues
   ```python
    @classmethod
       def extract_from(
           cls,
           parameterset: ParameterSet | Sequence[object] | object,
           force_tuple: bool = False,
       ) -> ParameterSet:
           """Extract from an object or objects.
   
           :param parameterset:
               A legacy style parameterset that may or may not be a tuple,
               and may or may not be wrapped into a mess of mark objects.
   
           :param force_tuple:
               Enforce tuple wrapping so single argument tuple values
               don't get decomposed and break tests.
           """
           if isinstance(parameterset, cls):
               return parameterset
           if force_tuple:
               return cls.param(parameterset)
           else:
               # TODO: Refactor to fix this type-ignore. Currently the following
               # passes type-checking but crashes:
               #
               #   @pytest.mark.parametrize(('x', 'y'), [1, 2])
               #   def test_foo(x, y): pass
               return cls(parameterset, marks=[], id=None)  # type: ignore[arg-type]
   ```
   Here, "contain" force_tuple is true, param.value becomes (object(),)=>len should be 1.
   (contain, ) force_tuple is false, so I think it go else and param.values is object(), and len(object())->failed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "KoviAnusha (via GitHub)" <gi...@apache.org>.
KoviAnusha commented on code in PR #57833:
URL: https://github.com/apache/airflow/pull/57833#discussion_r2492335366


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -342,7 +342,7 @@ def test_json_exc(structlog_config, get_logger, monkeypatch):
 
 
 @pytest.mark.parametrize(
-    ("levels",),
+    "levels",

Review Comment:
   Agree. Do you think we should add it as a comment to note this point for future purposes?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #57833:
URL: https://github.com/apache/airflow/pull/57833#discussion_r2495639444


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -342,7 +342,7 @@ def test_json_exc(structlog_config, get_logger, monkeypatch):
 
 
 @pytest.mark.parametrize(
-    ("levels",),
+    "levels",

Review Comment:
   @xchwan :  check this one out.  It required Kovi to make the string to a single tuple.   I wonder what's different between this one and [yours](https://github.com/apache/airflow/pull/57842#discussion_r2495538821)?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #57833:
URL: https://github.com/apache/airflow/pull/57833#discussion_r2495573814


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -342,7 +342,7 @@ def test_json_exc(structlog_config, get_logger, monkeypatch):
 
 
 @pytest.mark.parametrize(
-    ("levels",),
+    "levels",

Review Comment:
   Nah, I guess it's fine.  If we're going to standardize, then I guess we're going to standardize.  :sweat_smile: 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "xchwan (via GitHub)" <gi...@apache.org>.
xchwan commented on PR #57833:
URL: https://github.com/apache/airflow/pull/57833#issuecomment-3492551549

   I find description 
   PT011: all instances of @pytest.mark.parametrize names should be a tuple
   should be PT006


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi merged PR #57833:
URL: https://github.com/apache/airflow/pull/57833


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enable PT006 rule to kubernetes-tests, performance, airflow-ctl, docker-tests & shared [airflow]

Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #57833:
URL: https://github.com/apache/airflow/pull/57833#discussion_r2492305634


##########
shared/logging/tests/logging/test_structlog.py:
##########
@@ -342,7 +342,7 @@ def test_json_exc(structlog_config, get_logger, monkeypatch):
 
 
 @pytest.mark.parametrize(
-    ("levels",),
+    "levels",

Review Comment:
   That's a shame it forces a tuple on single values.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org