Remove duplicated conversion of pytest.fixture() params argument
The FixtureFunctionMarker attrs class already converts the params itself. When adding types, the previous converter composition causes some type error, but extracting it to a standalone function fixes the issue (a lambda is not supported by the mypy plugin, currently).
This commit is contained in:
parent
1bd7d025d9
commit
8bcf1d6de1
|
@ -1103,6 +1103,12 @@ def _ensure_immutable_ids(
|
||||||
return tuple(ids)
|
return tuple(ids)
|
||||||
|
|
||||||
|
|
||||||
|
def _params_converter(
|
||||||
|
params: Optional[Iterable[object]],
|
||||||
|
) -> Optional[Tuple[object, ...]]:
|
||||||
|
return tuple(params) if params is not None else None
|
||||||
|
|
||||||
|
|
||||||
def wrap_function_to_error_out_if_called_directly(function, fixture_marker):
|
def wrap_function_to_error_out_if_called_directly(function, fixture_marker):
|
||||||
"""Wrap the given fixture function so we can raise an error about it being called directly,
|
"""Wrap the given fixture function so we can raise an error about it being called directly,
|
||||||
instead of used as an argument in a test function.
|
instead of used as an argument in a test function.
|
||||||
|
@ -1127,8 +1133,8 @@ def wrap_function_to_error_out_if_called_directly(function, fixture_marker):
|
||||||
|
|
||||||
@attr.s(frozen=True)
|
@attr.s(frozen=True)
|
||||||
class FixtureFunctionMarker:
|
class FixtureFunctionMarker:
|
||||||
scope = attr.ib()
|
scope = attr.ib(type="Union[_Scope, Callable[[str, Config], _Scope]]")
|
||||||
params = attr.ib(converter=attr.converters.optional(tuple))
|
params = attr.ib(type=Optional[Tuple[object, ...]], converter=_params_converter)
|
||||||
autouse = attr.ib(type=bool, default=False)
|
autouse = attr.ib(type=bool, default=False)
|
||||||
ids = attr.ib(
|
ids = attr.ib(
|
||||||
type=Union[
|
type=Union[
|
||||||
|
@ -1168,7 +1174,7 @@ def fixture(
|
||||||
fixture_function=None,
|
fixture_function=None,
|
||||||
*args: Any,
|
*args: Any,
|
||||||
scope: "Union[_Scope, Callable[[str, Config], _Scope]]" = "function",
|
scope: "Union[_Scope, Callable[[str, Config], _Scope]]" = "function",
|
||||||
params=None,
|
params: Optional[Iterable[object]] = None,
|
||||||
autouse: bool = False,
|
autouse: bool = False,
|
||||||
ids: Optional[
|
ids: Optional[
|
||||||
Union[
|
Union[
|
||||||
|
@ -1274,9 +1280,6 @@ def fixture(
|
||||||
warnings.warn(FIXTURE_POSITIONAL_ARGUMENTS, stacklevel=2)
|
warnings.warn(FIXTURE_POSITIONAL_ARGUMENTS, stacklevel=2)
|
||||||
# End backward compatiblity.
|
# End backward compatiblity.
|
||||||
|
|
||||||
if params is not None:
|
|
||||||
params = list(params)
|
|
||||||
|
|
||||||
fixture_marker = FixtureFunctionMarker(
|
fixture_marker = FixtureFunctionMarker(
|
||||||
scope=scope, params=params, autouse=autouse, ids=ids, name=name,
|
scope=scope, params=params, autouse=autouse, ids=ids, name=name,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue