diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index 8fdacfcc1..4aaa94452 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -92,9 +92,7 @@ def warning_record_to_str(warning_message: warnings.WarningMessage) -> str: formatted_tb = "\n".join(tb.format()) # Use a leading new line to better separate the (large) output # from the traceback to the previous warning text. - msg += ( - f"\nObject allocated at (most recent call first):\n{formatted_tb}" - ) + msg += f"\nObject allocated at:\n{formatted_tb}" else: # No need for a leading new line. url = "https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings" diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 4d3634991..8b841d638 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -819,7 +819,7 @@ def test_resource_warning(pytester: Pytester, monkeypatch: pytest.MonkeyPatch) - expected_extra = ( [ "*ResourceWarning* unclosed file*", - "*Object allocated at (most recent call first)*", + "*Object allocated at*", ] if has_tracemalloc else []