Skip to content

Commit 27d1a2f

Browse files
committed
Get any contained func when marking
1 parent ec34f1c commit 27d1a2f

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

changelog/12863.bugfix.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix :func:`pytest.mark.parametrize` marker placed above `@staticmethod`
1+
Fix :func:`pytest.mark.parametrize <pytest.mark.xfail>` marker placed above `@staticmethod`

src/_pytest/mark/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def __call__(self, *args: object, **kwargs: object):
349349
if args and not kwargs:
350350
func = args[0]
351351
is_class = inspect.isclass(func)
352-
marking_func = func.__func__ if isinstance(func, staticmethod) else func
352+
marking_func = getattr(func, "__func__", func)
353353
if len(args) == 1 and (istestfunc(marking_func) or is_class):
354354
store_mark(marking_func, self.mark, stacklevel=3)
355355
return func

testing/test_mark.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,11 +1235,16 @@ def test_mark_parametrize_over_staticmethod(pytester: Pytester) -> None:
12351235
import pytest
12361236
12371237
class TestClass:
1238+
@pytest.mark.parametrize("value", [1, 2])
1239+
@classmethod
1240+
def test_classmethod_wrapper(cls, value: int):
1241+
assert value in [1, 2]
1242+
12381243
@pytest.mark.parametrize("value", [1, 2])
12391244
@staticmethod
1240-
def test_foo(value: int):
1245+
def test_staticmethod_wrapper(value: int):
12411246
assert value in [1, 2]
12421247
"""
12431248
)
12441249
result = pytester.runpytest(foo)
1245-
result.assert_outcomes(passed=2)
1250+
result.assert_outcomes(passed=4)

0 commit comments

Comments
 (0)