From 03dc5ae5a1f42d1480a0c19a04a33e2fa5c33736 Mon Sep 17 00:00:00 2001 From: Allan Lewis Date: Tue, 8 Oct 2019 11:29:55 +0100 Subject: [PATCH] MarkGenerator: Report unknown mark warning at caller level Currently, `PytestUnknownMarkWarning` is reported at the level of `MarkGenerator`, which is unhelpful to callers as the warning is shown as being "caused" by pytest. This commit therefore increases the stack level passed to the warning call to 2, which will make the warning log as being "caused" by the caller, which is much more helpful. Resolves #5928. --- changelog/5928.bugfix.rst | 1 + src/_pytest/mark/structures.py | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/5928.bugfix.rst diff --git a/changelog/5928.bugfix.rst b/changelog/5928.bugfix.rst new file mode 100644 index 00000000000..fbc53757d84 --- /dev/null +++ b/changelog/5928.bugfix.rst @@ -0,0 +1 @@ +Report ``PytestUnknownMarkWarning`` at the level of the user's code, not ``pytest``'s. diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 2cab96d675a..4d5f706a259 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -323,6 +323,7 @@ def __getattr__(self, name: str) -> MarkDecorator: "custom marks to avoid this warning - for details, see " "https://docs.pytest.org/en/latest/mark.html" % name, PytestUnknownMarkWarning, + 2, ) return MarkDecorator(Mark(name, (), {}))