-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
code: do not truncate args in output when running with -vvv #12241
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 1 commit
6aca93b
fa769e2
85c90c5
9b69bba
1f19489
d4ed4bf
fd1d2de
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -448,6 +448,11 @@ | |||||||||||
else: | ||||||||||||
truncate_locals = True | ||||||||||||
|
||||||||||||
if self.config.getoption("verbose", 0) > 2: | ||||||||||||
truncate_args = False | ||||||||||||
else: | ||||||||||||
truncate_args = True | ||||||||||||
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. We can use a ternary here to make the code a bit more succint, while also cheating a bit on the coverage.
Suggested change
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. Thank you! I changed the code accordingly, this looks much nicer indeed. |
||||||||||||
|
||||||||||||
# excinfo.getrepr() formats paths relative to the CWD if `abspath` is False. | ||||||||||||
# It is possible for a fixture/test to change the CWD while this code runs, which | ||||||||||||
# would then result in the user seeing confusing paths in the failure message. | ||||||||||||
|
@@ -466,6 +471,7 @@ | |||||||||||
style=style, | ||||||||||||
tbfilter=tbfilter, | ||||||||||||
truncate_locals=truncate_locals, | ||||||||||||
truncate_args=truncate_args, | ||||||||||||
) | ||||||||||||
|
||||||||||||
def repr_failure( | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -708,6 +708,28 @@ def test_repr_local_truncated(self) -> None: | |
assert full_reprlocals.lines | ||
assert full_reprlocals.lines[0] == "l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" | ||
|
||
def test_repr_args_not_truncated(self, importasmod) -> None: | ||
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. Love the unittest! Perhaps, in addition, we should have an integration test using 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. Thanks for the pointer! I added one now, please let me know if I put it into the right place (not 100% certain about this, happy to switch/move as needed). 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. Looks good, thanks! |
||
mod = importasmod( | ||
""" | ||
def func1(m): | ||
raise ValueError("hello\\nworld") | ||
""" | ||
) | ||
excinfo = pytest.raises(ValueError, mod.func1, "m" * 500) | ||
excinfo.traceback = excinfo.traceback.filter(excinfo) | ||
entry = excinfo.traceback[-1] | ||
p = FormattedExcinfo(funcargs=True, truncate_args=True) | ||
reprfuncargs = p.repr_args(entry) | ||
assert reprfuncargs is not None | ||
assert len(reprfuncargs.args[0][1]) < 500 | ||
assert "..." in reprfuncargs.args[0][1] | ||
# again without truncate | ||
p = FormattedExcinfo(funcargs=True, truncate_args=False) | ||
reprfuncargs = p.repr_args(entry) | ||
assert reprfuncargs is not None | ||
assert reprfuncargs.args[0] == ("m", repr("m" * 500)) | ||
assert "..." not in reprfuncargs.args[0][1] | ||
|
||
def test_repr_tracebackentry_lines(self, importasmod) -> None: | ||
mod = importasmod( | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about still calling
saferepr
, but passingmax_size=None
iftruncate_args
isFalse
?