@@ -2176,11 +2176,13 @@ def test_function(foo, bar):
21762176 ]
21772177 )
21782178
2179- def test_depend_on_marks (self , pytester : Pytester ) -> None :
2179+ def test_hook_depends_on_marks (self , pytester : Pytester ) -> None :
21802180 pytester .makepyfile (
21812181 """
21822182 import pytest
21832183
2184+ # Note: without hookimpl, the hook goes after the parametrize mark.
2185+ @pytest.hookimpl(trylast=True)
21842186 def pytest_generate_tests(metafunc: pytest.Metafunc):
21852187 if "bar" in metafunc.fixturenames:
21862188 base_bar_marks = list(metafunc.definition.iter_markers("bar_params"))
@@ -2211,16 +2213,60 @@ def test_function(foo, bar):
22112213 result = pytester .runpytest ("-vv" , "-s" )
22122214 result .stdout .fnmatch_lines (
22132215 [
2214- "test_depend_on_marks .py::test_function[a-x] PASSED" ,
2215- "test_depend_on_marks .py::test_function[b-x] PASSED" ,
2216- "test_depend_on_marks .py::test_function[b-y] PASSED" ,
2217- "test_depend_on_marks .py::test_function[b-z] PASSED" ,
2218- "test_depend_on_marks .py::test_function[c-x] PASSED" ,
2219- "test_depend_on_marks .py::test_function[c-w] PASSED" ,
2216+ "test_hook_depends_on_marks .py::test_function[a-x] PASSED" ,
2217+ "test_hook_depends_on_marks .py::test_function[b-x] PASSED" ,
2218+ "test_hook_depends_on_marks .py::test_function[b-y] PASSED" ,
2219+ "test_hook_depends_on_marks .py::test_function[b-z] PASSED" ,
2220+ "test_hook_depends_on_marks .py::test_function[c-x] PASSED" ,
2221+ "test_hook_depends_on_marks .py::test_function[c-w] PASSED" ,
22202222 "*= 6 passed in *" ,
22212223 ]
22222224 )
22232225
2226+ @pytest .mark .skip (reason = ":(" )
2227+ def test_mark_depends_on_hooks (self , pytester : Pytester ) -> None :
2228+ pytester .makepyfile (
2229+ """
2230+ import pytest
2231+
2232+ # Note: with tryfirst, the hook goes before the parametrize mark.
2233+ @pytest.hookimpl(wrapper=True)
2234+ def pytest_generate_tests(metafunc: pytest.Metafunc):
2235+ if "foo" in metafunc.fixturenames:
2236+ metafunc.parametrize(
2237+ "foo",
2238+ [
2239+ pytest.param("a", marks=[pytest.mark.bar_params("x", "y")]),
2240+ pytest.param("b", marks=[pytest.mark.bar_params("z")]),
2241+ ],
2242+ )
2243+ return (yield)
2244+
2245+
2246+ def gen_params(callspec: pytest.CallSpec):
2247+ bar_marks = [
2248+ mark
2249+ for mark in callspec.marks
2250+ if mark.name == "bar_params"
2251+ ]
2252+ return [arg for mark in bar_marks for arg in mark.args]
2253+
2254+
2255+ @pytest.mark.parametrize("bar", gen_params)
2256+ def test_function(foo, bar):
2257+ pass
2258+ """
2259+ )
2260+ result = pytester .runpytest ("-vv" , "-s" )
2261+ result .stdout .fnmatch_lines (
2262+ [
2263+ "test_mark_depends_on_hooks.py::test_function[a-x] PASSED" ,
2264+ "test_mark_depends_on_hooks.py::test_function[a-y] PASSED" ,
2265+ "test_mark_depends_on_hooks.py::test_function[b-z] PASSED" ,
2266+ "*= 3 passed in *" ,
2267+ ]
2268+ )
2269+
22242270 def test_id_and_marks (self , pytester : Pytester ) -> None :
22252271 pytester .makepyfile (
22262272 """
0 commit comments