diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index 388949bed..3be1648fe 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -168,4 +168,5 @@ def warn_explicit_for(method: FunctionType, message: PytestWarning) -> None: lineno=lineno, ) except Warning as w: + # If warnings are errors (e.g. -Werror), location information gets lost, so we add it to the message. raise type(w)(f"{w}\n at {filename}:{lineno}") from None