diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-14 14:36:14 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-03-14 14:36:14 +0300 |
commit | e55fb55efda71cea0cd9c5fdafa41af406aef5bf (patch) | |
tree | 664dd8ed9a31584f9373593983273c9de2f13e7b /contrib/python/pytest/py3/_pytest/warnings.py | |
parent | 95e3624686fdca2887aa10594ee976cfddd32e38 (diff) | |
download | ydb-e55fb55efda71cea0cd9c5fdafa41af406aef5bf.tar.gz |
intermediate changes
ref:8379e897e1f4fa0d71bb778a7c8bc68cb5e2f5ea
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/warnings.py')
-rw-r--r-- | contrib/python/pytest/py3/_pytest/warnings.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/contrib/python/pytest/py3/_pytest/warnings.py b/contrib/python/pytest/py3/_pytest/warnings.py index c0c946cbde..4aaa944529 100644 --- a/contrib/python/pytest/py3/_pytest/warnings.py +++ b/contrib/python/pytest/py3/_pytest/warnings.py @@ -49,8 +49,6 @@ def catch_warnings_for_item( warnings.filterwarnings("always", category=DeprecationWarning) warnings.filterwarnings("always", category=PendingDeprecationWarning) - warnings.filterwarnings("error", category=pytest.PytestRemovedIn7Warning) - apply_warning_filters(config_filters, cmdline_filters) # apply filters from "filterwarnings" marks @@ -63,14 +61,6 @@ def catch_warnings_for_item( yield for warning_message in log: - ihook.pytest_warning_captured.call_historic( - kwargs=dict( - warning_message=warning_message, - when=when, - item=item, - location=None, - ) - ) ihook.pytest_warning_recorded.call_historic( kwargs=dict( warning_message=warning_message, @@ -91,6 +81,23 @@ def warning_record_to_str(warning_message: warnings.WarningMessage) -> str: warning_message.lineno, warning_message.line, ) + if warning_message.source is not None: + try: + import tracemalloc + except ImportError: + pass + else: + tb = tracemalloc.get_object_traceback(warning_message.source) + if tb is not None: + 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:\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" + msg += "Enable tracemalloc to get traceback where the object was allocated.\n" + msg += f"See {url} for more info." return msg |