From 0d7270e2c40faa470a45b187c11a18c807179314 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 12:10:31 +0200 Subject: [PATCH 01/19] Add idx to hook callback --- src/_pytest/hookspec.py | 3 ++- src/_pytest/python.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 99614899994..4e55b2f9a7f 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -588,7 +588,7 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: @hookspec(firstresult=True) -def pytest_make_parametrize_id(config: Config, val: object, argname: str) -> str | None: +def pytest_make_parametrize_id(config: Config, val: object, argname: str, idx: int) -> str | None: """Return a user-friendly string representation of the given ``val`` that will be used by @pytest.mark.parametrize calls, or None if the hook doesn't know about ``val``. @@ -600,6 +600,7 @@ def pytest_make_parametrize_id(config: Config, val: object, argname: str) -> str :param config: The pytest config object. :param val: The parametrized value. :param argname: The automatic parameter name produced by pytest. + :param idx: The iteration number of parameterized tests as calculated by pytest. Use in conftest plugins ======================= diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 9182ce7dfe9..8858522640b 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -939,7 +939,7 @@ def _idval(self, val: object, argname: str, idx: int) -> str: idval = self._idval_from_function(val, argname, idx) if idval is not None: return idval - idval = self._idval_from_hook(val, argname) + idval = self._idval_from_hook(val, argname, idx) if idval is not None: return idval idval = self._idval_from_value(val) @@ -963,12 +963,12 @@ def _idval_from_function(self, val: object, argname: str, idx: int) -> str | Non return None return self._idval_from_value(id) - def _idval_from_hook(self, val: object, argname: str) -> str | None: + def _idval_from_hook(self, val: object, argname: str, idx: int) -> str | None: """Try to make an ID for a parameter in a ParameterSet by calling the :hook:`pytest_make_parametrize_id` hook.""" if self.config: id: str | None = self.config.hook.pytest_make_parametrize_id( - config=self.config, val=val, argname=argname + config=self.config, val=val, argname=argname, idx=idx ) return id return None From d847ccb3555f1683ff79fa943069c2aba5512e68 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 12:10:52 +0200 Subject: [PATCH 02/19] Add argname and idx to ID callable arguments --- src/_pytest/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 8858522640b..726eb7f78ca 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -953,7 +953,7 @@ def _idval_from_function(self, val: object, argname: str, idx: int) -> str | Non if self.idfn is None: return None try: - id = self.idfn(val) + id = self.idfn(val, argname, idx) except Exception as e: prefix = f"{self.nodeid}: " if self.nodeid is not None else "" msg = "error raised while trying to determine id of parameter '{}' at position {}" From 591c2b475089fec90708a0c3381626fcf7d9f743 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:14:13 +0000 Subject: [PATCH 03/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/hookspec.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 4e55b2f9a7f..791c75046b4 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -588,7 +588,9 @@ def pytest_generate_tests(metafunc: Metafunc) -> None: @hookspec(firstresult=True) -def pytest_make_parametrize_id(config: Config, val: object, argname: str, idx: int) -> str | None: +def pytest_make_parametrize_id( + config: Config, val: object, argname: str, idx: int +) -> str | None: """Return a user-friendly string representation of the given ``val`` that will be used by @pytest.mark.parametrize calls, or None if the hook doesn't know about ``val``. From 1e9c984c53db10e2be0f57abb16b894ba7a407e1 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 12:28:51 +0200 Subject: [PATCH 04/19] Fixed idfn type hints --- src/_pytest/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 726eb7f78ca..c8d92503f93 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -869,7 +869,7 @@ class IdMaker: parametersets: Sequence[ParameterSet] # Optionally, a user-provided callable to make IDs for parameters in a # ParameterSet. - idfn: Callable[[Any], object | None] | None + idfn: Callable[[Any, str, int], object | None] | None # Optionally, explicit IDs for ParameterSets by index. ids: Sequence[object | None] | None # Optionally, the pytest config. From 87950b63517f35036bb34068cf2b0a51bff7ec95 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 12:42:19 +0200 Subject: [PATCH 05/19] Fixed test methods --- testing/python/metafunc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 2dd85607e71..921881433e7 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -514,7 +514,7 @@ def test_idmaker_enum(self) -> None: def test_idmaker_idfn(self) -> None: """#351""" - def ids(val: object) -> str | None: + def ids(val: object, argname: str, idx: int) -> str | None: if isinstance(val, Exception): return repr(val) return None @@ -537,7 +537,7 @@ def ids(val: object) -> str | None: def test_idmaker_idfn_unique_names(self) -> None: """#351""" - def ids(val: object) -> str: + def ids(val: object, argname: str, idx: int) -> str: return "a" result = IdMaker( @@ -585,7 +585,7 @@ def getini(self, name): result = IdMaker( ("a",), [pytest.param("string")], - lambda _: "ação", + lambda _, __, ___ : "ação", None, config, None, From a8693d2e4e3f818360bf49d69b359e3cbc3c50fd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:44:56 +0000 Subject: [PATCH 06/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- testing/python/metafunc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 921881433e7..3ffb843e462 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -585,7 +585,7 @@ def getini(self, name): result = IdMaker( ("a",), [pytest.param("string")], - lambda _, __, ___ : "ação", + lambda _, __, ___: "ação", None, config, None, From a778e57b174ac959e9ecd62f1f1a5b3d2b493bae Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 12:46:02 +0200 Subject: [PATCH 07/19] Added changelog item --- changelog/12628.feature.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/12628.feature.rst diff --git a/changelog/12628.feature.rst b/changelog/12628.feature.rst new file mode 100644 index 00000000000..01d23a29313 --- /dev/null +++ b/changelog/12628.feature.rst @@ -0,0 +1,3 @@ +Existing parameters (argname and case index) are passed to hook and idfn for parameterized test ID creation. + +-- by :user:`nicoloborghi` \ No newline at end of file From 103d2bd81662c8adeb12b245daa1f9b86d352643 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:46:49 +0000 Subject: [PATCH 08/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- changelog/12628.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/12628.feature.rst b/changelog/12628.feature.rst index 01d23a29313..b565cb89938 100644 --- a/changelog/12628.feature.rst +++ b/changelog/12628.feature.rst @@ -1,3 +1,3 @@ Existing parameters (argname and case index) are passed to hook and idfn for parameterized test ID creation. --- by :user:`nicoloborghi` \ No newline at end of file +-- by :user:`nicoloborghi` From c7009761b2505b188f806a1ed09c1223d0085a42 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 12:50:33 +0200 Subject: [PATCH 09/19] Fixed parameter type in IdMaker instance creation --- src/_pytest/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index c8d92503f93..5d6e03f2ba8 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1315,7 +1315,7 @@ def parametrize( def _resolve_parameter_set_ids( self, argnames: Sequence[str], - ids: Iterable[object | None] | Callable[[Any], object | None] | None, + ids: Iterable[object | None] | Callable[[Any, str, int], object | None] | None, parametersets: Sequence[ParameterSet], nodeid: str, ) -> list[str]: From 929949f27f9cd9c91f533e495b2416e04fcbf41d Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 12:52:27 +0200 Subject: [PATCH 10/19] Fixed parameter type --- src/_pytest/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 5d6e03f2ba8..1023f6ecb35 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1136,7 +1136,7 @@ def parametrize( argnames: str | Sequence[str], argvalues: Iterable[ParameterSet | Sequence[object] | object], indirect: bool | Sequence[str] = False, - ids: Iterable[object | None] | Callable[[Any], object | None] | None = None, + ids: Iterable[object | None] | Callable[[Any, str, int], object | None] | None = None, scope: _ScopeName | None = None, *, _param_mark: Mark | None = None, From a698b94ed38e3165459e4fa259559735a2d41ad9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:52:49 +0000 Subject: [PATCH 11/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/python.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 1023f6ecb35..6ff114d2285 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1136,7 +1136,9 @@ def parametrize( argnames: str | Sequence[str], argvalues: Iterable[ParameterSet | Sequence[object] | object], indirect: bool | Sequence[str] = False, - ids: Iterable[object | None] | Callable[[Any, str, int], object | None] | None = None, + ids: Iterable[object | None] + | Callable[[Any, str, int], object | None] + | None = None, scope: _ScopeName | None = None, *, _param_mark: Mark | None = None, From 10603cd95546b2d40e29fec4e1561f8d7aeab065 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 13:00:59 +0200 Subject: [PATCH 12/19] Fixed fixture type hint --- src/_pytest/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 7d0b40b150a..529a2d3129f 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -955,7 +955,7 @@ def __init__( func: _FixtureFunc[FixtureValue], scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] | None, params: Sequence[object] | None, - ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, + ids: tuple[object | None, ...] | Callable[[Any, str, int], object | None] | None = None, *, _ispytest: bool = False, ) -> None: From 9b329f05ca70342b5aaa2355310598a4849cc40c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:02:36 +0000 Subject: [PATCH 13/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/fixtures.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 529a2d3129f..3571a0a1c3f 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -955,7 +955,9 @@ def __init__( func: _FixtureFunc[FixtureValue], scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] | None, params: Sequence[object] | None, - ids: tuple[object | None, ...] | Callable[[Any, str, int], object | None] | None = None, + ids: tuple[object | None, ...] + | Callable[[Any, str, int], object | None] + | None = None, *, _ispytest: bool = False, ) -> None: From 024e7bd4d04b29770a54033e8c41d7b0914ee658 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 13:05:22 +0200 Subject: [PATCH 14/19] Fixed type hint and argument number --- src/_pytest/fixtures.py | 2 +- src/_pytest/setuponly.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 529a2d3129f..441c73c81bd 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1633,7 +1633,7 @@ def _register_fixture( nodeid: str | None, scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] = "function", params: Sequence[object] | None = None, - ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, + ids: tuple[object | None, ...] | Callable[[Any, str, int], object | None] | None = None, autouse: bool = False, ) -> None: """Register a fixture diff --git a/src/_pytest/setuponly.py b/src/_pytest/setuponly.py index de297f408d3..3a2a88f944d 100644 --- a/src/_pytest/setuponly.py +++ b/src/_pytest/setuponly.py @@ -41,7 +41,7 @@ def pytest_fixture_setup( # display it now and during the teardown (in .finish()). if fixturedef.ids: if callable(fixturedef.ids): - param = fixturedef.ids(request.param) + param = fixturedef.ids(request.param, request.fixturename, request.param_index) else: param = fixturedef.ids[request.param_index] else: From 441fad491c3081bdfdcc3f8dfdc2e0eeb651e490 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:05:46 +0000 Subject: [PATCH 15/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/fixtures.py | 4 +++- src/_pytest/setuponly.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 920fa106200..f8223040407 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1635,7 +1635,9 @@ def _register_fixture( nodeid: str | None, scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] = "function", params: Sequence[object] | None = None, - ids: tuple[object | None, ...] | Callable[[Any, str, int], object | None] | None = None, + ids: tuple[object | None, ...] + | Callable[[Any, str, int], object | None] + | None = None, autouse: bool = False, ) -> None: """Register a fixture diff --git a/src/_pytest/setuponly.py b/src/_pytest/setuponly.py index 3a2a88f944d..6ef2605b4f2 100644 --- a/src/_pytest/setuponly.py +++ b/src/_pytest/setuponly.py @@ -41,7 +41,9 @@ def pytest_fixture_setup( # display it now and during the teardown (in .finish()). if fixturedef.ids: if callable(fixturedef.ids): - param = fixturedef.ids(request.param, request.fixturename, request.param_index) + param = fixturedef.ids( + request.param, request.fixturename, request.param_index + ) else: param = fixturedef.ids[request.param_index] else: From 0f3ec5b381c8ffd14d8968ab0b8926596378a3c9 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 13:15:13 +0200 Subject: [PATCH 16/19] Fixed more type hints --- src/_pytest/fixtures.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 920fa106200..da627d4d4ee 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1182,7 +1182,7 @@ class FixtureFunctionMarker: scope: _ScopeName | Callable[[str, Config], _ScopeName] params: tuple[object, ...] | None autouse: bool = False - ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None + ids: tuple[object | None, ...] | Callable[[Any, str, int], object | None] | None = None name: str | None = None _ispytest: dataclasses.InitVar[bool] = False @@ -1224,7 +1224,7 @@ def fixture( scope: _ScopeName | Callable[[str, Config], _ScopeName] = ..., params: Iterable[object] | None = ..., autouse: bool = ..., - ids: Sequence[object | None] | Callable[[Any], object | None] | None = ..., + ids: Sequence[object | None] | Callable[[Any, str, int], object | None] | None = ..., name: str | None = ..., ) -> FixtureFunction: ... @@ -1236,7 +1236,7 @@ def fixture( scope: _ScopeName | Callable[[str, Config], _ScopeName] = ..., params: Iterable[object] | None = ..., autouse: bool = ..., - ids: Sequence[object | None] | Callable[[Any], object | None] | None = ..., + ids: Sequence[object | None] | Callable[[Any, str, int], object | None] | None = ..., name: str | None = None, ) -> FixtureFunctionMarker: ... @@ -1247,7 +1247,7 @@ def fixture( scope: _ScopeName | Callable[[str, Config], _ScopeName] = "function", params: Iterable[object] | None = None, autouse: bool = False, - ids: Sequence[object | None] | Callable[[Any], object | None] | None = None, + ids: Sequence[object | None] | Callable[[Any, str, int], object | None] | None = None, name: str | None = None, ) -> FixtureFunctionMarker | FixtureFunction: """Decorator to mark a fixture factory function. From a2e18686a8476a30bf355c6afa9161cdc868ed68 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:15:36 +0000 Subject: [PATCH 17/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/fixtures.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 466cd443a39..6baf9e76e2a 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1182,7 +1182,9 @@ class FixtureFunctionMarker: scope: _ScopeName | Callable[[str, Config], _ScopeName] params: tuple[object, ...] | None autouse: bool = False - ids: tuple[object | None, ...] | Callable[[Any, str, int], object | None] | None = None + ids: tuple[object | None, ...] | Callable[[Any, str, int], object | None] | None = ( + None + ) name: str | None = None _ispytest: dataclasses.InitVar[bool] = False @@ -1224,7 +1226,9 @@ def fixture( scope: _ScopeName | Callable[[str, Config], _ScopeName] = ..., params: Iterable[object] | None = ..., autouse: bool = ..., - ids: Sequence[object | None] | Callable[[Any, str, int], object | None] | None = ..., + ids: Sequence[object | None] + | Callable[[Any, str, int], object | None] + | None = ..., name: str | None = ..., ) -> FixtureFunction: ... @@ -1236,7 +1240,9 @@ def fixture( scope: _ScopeName | Callable[[str, Config], _ScopeName] = ..., params: Iterable[object] | None = ..., autouse: bool = ..., - ids: Sequence[object | None] | Callable[[Any, str, int], object | None] | None = ..., + ids: Sequence[object | None] + | Callable[[Any, str, int], object | None] + | None = ..., name: str | None = None, ) -> FixtureFunctionMarker: ... @@ -1247,7 +1253,9 @@ def fixture( scope: _ScopeName | Callable[[str, Config], _ScopeName] = "function", params: Iterable[object] | None = None, autouse: bool = False, - ids: Sequence[object | None] | Callable[[Any, str, int], object | None] | None = None, + ids: Sequence[object | None] + | Callable[[Any, str, int], object | None] + | None = None, name: str | None = None, ) -> FixtureFunctionMarker | FixtureFunction: """Decorator to mark a fixture factory function. From 9e0de13aaa38d0e2bf3bc78a8a8ef67b71b96895 Mon Sep 17 00:00:00 2001 From: Nicolo_Borghi Date: Thu, 18 Jul 2024 14:25:14 +0200 Subject: [PATCH 18/19] Fixing types and typehints --- src/_pytest/setuponly.py | 2 +- testing/typing_checks.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_pytest/setuponly.py b/src/_pytest/setuponly.py index 6ef2605b4f2..da598c5ed7c 100644 --- a/src/_pytest/setuponly.py +++ b/src/_pytest/setuponly.py @@ -42,7 +42,7 @@ def pytest_fixture_setup( if fixturedef.ids: if callable(fixturedef.ids): param = fixturedef.ids( - request.param, request.fixturename, request.param_index + request.param, request.fixturename or "", request.param_index ) else: param = fixturedef.ids[request.param_index] diff --git a/testing/typing_checks.py b/testing/typing_checks.py index d4d6a97aea6..4208ab52b36 100644 --- a/testing/typing_checks.py +++ b/testing/typing_checks.py @@ -8,7 +8,7 @@ from __future__ import annotations import contextlib -from typing import Optional +from typing import Optional, cast, Callable, Any from typing_extensions import assert_type @@ -23,7 +23,7 @@ def check_mark_xfail_raises() -> None: # Issue #7494. -@pytest.fixture(params=[(0, 0), (1, 1)], ids=lambda x: str(x[0])) +@pytest.fixture(params=[(0, 0), (1, 1)], ids=cast(Callable[[Any, str, int], object | None] | None, lambda x, _, __: str(x[0]))) def check_fixture_ids_callable() -> None: pass From 07ff3b37d00f824d49595e87c246c352255670ec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2024 12:25:40 +0000 Subject: [PATCH 19/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/setuponly.py | 4 +++- testing/typing_checks.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/_pytest/setuponly.py b/src/_pytest/setuponly.py index da598c5ed7c..c9bac4bfa66 100644 --- a/src/_pytest/setuponly.py +++ b/src/_pytest/setuponly.py @@ -42,7 +42,9 @@ def pytest_fixture_setup( if fixturedef.ids: if callable(fixturedef.ids): param = fixturedef.ids( - request.param, request.fixturename or "", request.param_index + request.param, + request.fixturename or "", + request.param_index, ) else: param = fixturedef.ids[request.param_index] diff --git a/testing/typing_checks.py b/testing/typing_checks.py index 4208ab52b36..e575fbe7d63 100644 --- a/testing/typing_checks.py +++ b/testing/typing_checks.py @@ -8,7 +8,10 @@ from __future__ import annotations import contextlib -from typing import Optional, cast, Callable, Any +from typing import Any +from typing import Callable +from typing import cast +from typing import Optional from typing_extensions import assert_type @@ -23,7 +26,12 @@ def check_mark_xfail_raises() -> None: # Issue #7494. -@pytest.fixture(params=[(0, 0), (1, 1)], ids=cast(Callable[[Any, str, int], object | None] | None, lambda x, _, __: str(x[0]))) +@pytest.fixture( + params=[(0, 0), (1, 1)], + ids=cast( + Callable[[Any, str, int], object | None] | None, lambda x, _, __: str(x[0]) + ), +) def check_fixture_ids_callable() -> None: pass