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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]