Skip to content

Commit

Permalink
ENH: Improve warning stacklevel
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Feb 20, 2024
1 parent 95f21f9 commit 715dbc0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def __call__(self, *args: object, **kwargs: object):
func = args[0]
is_class = inspect.isclass(func)
if len(args) == 1 and (istestfunc(func) or is_class):
store_mark(func, self.mark)
store_mark(func, self.mark, stacklevel=3)
return func
return self.with_args(*args, **kwargs)

Expand Down Expand Up @@ -410,7 +410,7 @@ def normalize_mark_list(
yield mark_obj


def store_mark(obj, mark: Mark) -> None:
def store_mark(obj, mark: Mark, *, stacklevel: int=2) -> None:
"""Store a Mark on an object.
This is used to implement the Mark declarations/decorators correctly.
Expand All @@ -420,7 +420,7 @@ def store_mark(obj, mark: Mark) -> None:
from ..fixtures import getfixturemarker

if getfixturemarker(obj) is not None:
warnings.warn(MARKED_FIXTURE, stacklevel=2)
warnings.warn(MARKED_FIXTURE, stacklevel=stacklevel)

# Always reassign name to avoid updating pytestmark in a reference that
# was only borrowed.
Expand Down

0 comments on commit 715dbc0

Please sign in to comment.