You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a detailed description of the bug or problem you are having
output of pip list from the virtual environment you are using
pytest and operating system versions
minimal example if possible
Description: get_closest_marker is working unexpectedly for me
I redefine the mark on the class in which the test is defined, but I get the mark of the parent of the class, i.e. a deeper mark than expected.
> assert some_mark.kwargs.get("data") == 1
E AssertionError: assert 0 == 1
E + where 0 = <built-in method get of dict object at 0x000001AC94A73740>('data')
E + where <built-in method get of dict object at 0x000001AC94A73740> = {'data': 0}.get
E + where {'data': 0} = Mark(name='some_mark', args=(), kwargs={'data': 0}).kwargs
In my understanding, the mark defined on TestChild is a closer mark than the mark defined on TestParent
@RonnyPfannschmidt, Hi!
I looked at the original issue #10447 for which this change was added.
I would like to note that in that task, it was about mark usefixtures.
In terms of inheritance, I agree that it is expected that a fixture from the parent will be called first, followed by a fixture from the child. But I would still expect that .get_closest_marker("usefixtures") would be exactly the usefixtures on the child.
I want to say that mark usefixture is a unique case. Perhaps it's worth processing usefixtures separately?
@RonnyPfannschmidt, Hi!
I created a PR that solves this problem.
I realize that I probably don't understand everything about pytest, and maybe I could have missed something, but all the tests passed. So if possible, please take a look at my PR
Activity
RonnyPfannschmidt commentedon Mar 27, 2026
#11155 added this to resolve a regression - https://xkcd.com/1172/ applies
i wonder if there’s a nicer way to do this
Wintreist commentedon Mar 27, 2026
@RonnyPfannschmidt, Hi!
I looked at the original issue #10447 for which this change was added.
I would like to note that in that task, it was about mark usefixtures.
In terms of inheritance, I agree that it is expected that a fixture from the parent will be called first, followed by a fixture from the child. But I would still expect that
.get_closest_marker("usefixtures")would be exactly theusefixtureson the child.I want to say that mark usefixture is a unique case. Perhaps it's worth processing
usefixturesseparately?RonnyPfannschmidt commentedon Mar 27, 2026
Yes a higher order plan is needed
The bugfix corrected a regression at the expense of clarity
The propper fix needs extra consideration
Wintreist commentedon Mar 28, 2026
@RonnyPfannschmidt, Hi!
I created a PR that solves this problem.
I realize that I probably don't understand everything about pytest, and maybe I could have missed something, but all the tests passed. So if possible, please take a look at my PR
Wintreist commentedon Jun 19, 2026
Hi!
I remind you about this problem, it was already ready to merge, but something got up.
Please make a decision on it.
RonnyPfannschmidt commentedon Jun 20, 2026
I created a draft that corrects the issue without reordering
fix: iter_markers/get_closest_marker now correctly returns closest MR…
doc: add changelog fragment for pytest-dev#14329
doc: add changelog fragment for pytest-dev#14329
fix: iter_markers/get_closest_marker now correctly returns closest MR…
doc: add changelog fragment for pytest-dev#14329
fix: iter_markers/get_closest_marker now correctly returns closest MR…
11 remaining items
fix: iter_markers/get_closest_marker now correctly returns closest MR…
doc: add changelog fragment for pytest-dev#14329
doc: credit Wintreist and document the preserved composition order
fix: iter_markers/get_closest_marker now correctly returns closest MR…
doc: add changelog fragment for pytest-dev#14329
doc: credit Wintreist and document the preserved composition order
fix: iter_markers/get_closest_marker now correctly returns closest MR…
doc: add changelog fragment for pytest-dev#14329
doc: credit Wintreist and document the preserved composition order
fix: iter_markers/get_closest_marker now correctly returns closest MR…
doc: add changelog fragment for pytest-dev#14329
doc: credit Wintreist and document the preserved composition order
Merge pull request #14630 from RonnyPfannschmidt/fix/iter-markers-mro…
RonnyPfannschmidt commentedon Nov 25, 2026
closed by #14630