-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Increase truncation threshold with -v, disable with -vv #8391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
By default, pytest will truncate long strings in assert errors so they don't clutter the output too much, | ||
currently at ``240`` characters by default. | ||
|
||
However, in some cases the longer output helps, or is even crucial, to diagnose a failure. Using ``-v`` will | ||
now increase the truncation threshold to ``2400`` characters, and ``-vv`` or higher will disable truncation entirely. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
from typing import TYPE_CHECKING | ||
from typing import Union | ||
|
||
from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE | ||
from _pytest._io.saferepr import saferepr | ||
from _pytest._version import version | ||
from _pytest.assertion import util | ||
|
@@ -427,7 +428,18 @@ def _saferepr(obj: object) -> str: | |
sequences, especially '\n{' and '\n}' are likely to be present in | ||
JSON reprs. | ||
""" | ||
return saferepr(obj).replace("\n", "\\n") | ||
maxsize = _get_maxsize_for_saferepr(util._config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This consults the Config at the time the test is run. Alternative is to consult the config at the time the test is rewritten, that is, make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I thought that too, however I realized assertion rewritten is cached, so if you invoke I injected the |
||
return saferepr(obj, maxsize=maxsize).replace("\n", "\\n") | ||
|
||
|
||
def _get_maxsize_for_saferepr(config: Optional[Config]) -> Optional[int]: | ||
"""Get `maxsize` configuration for saferepr based on the given config object.""" | ||
verbosity = config.getoption("verbose") if config is not None else 0 | ||
if verbosity >= 2: | ||
return None | ||
if verbosity >= 1: | ||
return DEFAULT_REPR_MAX_SIZE * 10 | ||
return DEFAULT_REPR_MAX_SIZE | ||
|
||
|
||
def _format_assertmsg(obj: object) -> str: | ||
|
Uh oh!
There was an error while loading. Please reload this page.