Skip to content

Commit 37cf659

Browse files
committed
More explicit edgecase of decorators
1 parent ec60713 commit 37cf659

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

changelog/12863.bugfix.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix :ref:`pytest.mark.parametrize <pytest.mark.parametrize ref>` marker placed above `@staticmethod`
1+
Fix applying markers, including :ref:`pytest.mark.parametrize <pytest.mark.parametrize ref>` when placed above `@staticmethod` or `@classmethod`.

src/_pytest/mark/structures.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,13 @@ 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 = getattr(func, "__func__", func)
353-
if len(args) == 1 and (istestfunc(marking_func) or is_class):
354-
store_mark(marking_func, self.mark, stacklevel=3)
352+
# For staticmethods/classmethods, the marks are eventually fetched from the
353+
# function object, not the descriptor, so unwrap.
354+
unwrapped_func = func
355+
if isinstance(func, (staticmethod, classmethod)):
356+
unwrapped_func = func.__func__
357+
if len(args) == 1 and (istestfunc(unwrapped_func) or is_class):
358+
store_mark(unwrapped_func, self.mark, stacklevel=3)
355359
return func
356360
return self.with_args(*args, **kwargs)
357361

testing/test_mark.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,6 @@ def test_attrs(self):
12281228
result.assert_outcomes(passed=1)
12291229

12301230

1231-
# @pytest.mark.issue("https://github.com/pytest-dev/pytest/issues/12863")
12321231
def test_mark_parametrize_over_staticmethod(pytester: Pytester) -> None:
12331232
"""Check that applying marks works as intended on classmethods and staticmethods.
12341233

0 commit comments

Comments
 (0)