Skip to content

Commit 495459d

Browse files
committed
Fix parametrized mark over staticmethod decorator
1 parent 28e1e25 commit 495459d

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Eric Yuan
150150
Erik Aronesty
151151
Erik Hasse
152152
Erik M. Bray
153+
Ethan Wass
153154
Evan Kepner
154155
Evgeny Seliverstov
155156
Fabian Sturm

changelog/12863.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :func:`pytest.mark.parametrize` marker placed above `@staticmethod`

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ disable = [
334334

335335
[tool.codespell]
336336
ignore-words-list = "afile,asend,asser,assertio,feld,hove,ned,noes,notin,paramete,parth,socio-economic,tesults,varius,wil"
337-
skip = "*/plugin_list.rst"
337+
skip = "AUTHORS,*/plugin_list.rst"
338338
write-changes = true
339339

340340
[tool.check-wheel-contents]

src/_pytest/mark/structures.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ def __call__(self, *args: object, **kwargs: object):
350350
func = args[0]
351351
is_class = inspect.isclass(func)
352352
if len(args) == 1 and (istestfunc(func) or is_class):
353-
store_mark(func, self.mark, stacklevel=3)
353+
if isinstance(func, staticmethod):
354+
# If the marker decorates a staticmethod, store on the test func
355+
store_mark(func.__func__, self.mark, stacklevel=3)
356+
else:
357+
store_mark(func, self.mark, stacklevel=3)
354358
return func
355359
return self.with_args(*args, **kwargs)
356360

testing/test_mark.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,3 +1226,20 @@ def test_attrs(self):
12261226
)
12271227
result = pytester.runpytest(foo)
12281228
result.assert_outcomes(passed=1)
1229+
1230+
1231+
# @pytest.mark.issue("https://github.com/pytest-dev/pytest/issues/12863")
1232+
def test_mark_parametrize_over_staticmethod(pytester: Pytester) -> None:
1233+
foo = pytester.makepyfile(
1234+
"""
1235+
import pytest
1236+
1237+
class TestClass:
1238+
@pytest.mark.parametrize("value", [1, 2])
1239+
@staticmethod
1240+
def test_foo(value: int):
1241+
assert value in [1, 2]
1242+
"""
1243+
)
1244+
result = pytester.runpytest(foo)
1245+
result.assert_outcomes(passed=2)

0 commit comments

Comments
 (0)