Skip to content
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

Avoid truncation when truncating means longer output #10446

Conversation

Pierre-Sassoulas
Copy link
Member

The full output of a test is no longer truncated if the truncation message would be longer than
the hidden text. The line number shown has also been fixed.

I also used f-string for faster string formatting in a previous commit, I don't think this warrant another MR though.

Closes #6267

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the avoid-truncation-when-truncating-means-longer-output branch from 4faa5c0 to 25fbd3f Compare October 30, 2022 05:47
@Pierre-Sassoulas
Copy link
Member Author

@nicoddemus anything I can do to make the review easier ? :)

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Pierre-Sassoulas, sorry for the delay and thanks for the ping.

LGTM, left a few small comments, please take a look. 👍

@@ -0,0 +1,2 @@
The full output of a test is no longer truncated if the truncation message would be longer than
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file would be better marked as improvement in the changelog, so can you please rename it to 6267.improvement.rst?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e7a48a2

src/_pytest/assertion/truncate.py Show resolved Hide resolved
src/_pytest/assertion/truncate.py Outdated Show resolved Hide resolved
# Add ellipsis to final line
truncated_explanation[-1] = truncated_explanation[-1] + "..."
# We reevaluate the need to truncate following removal of some lines
if len("".join(input_lines)) > tolerable_max_chars:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you use truncated_explanation here?

Suggested change
if len("".join(input_lines)) > tolerable_max_chars:
if len("".join(truncated_explanation)) > tolerable_max_chars:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, probably best to update the comment above:

# We reevaluate the need to truncate chars following removal of some lines

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch ! This led to further improvement in 4d2c40f

testing/test_assertion.py Outdated Show resolved Hide resolved
testing/test_assertion.py Outdated Show resolved Hide resolved
@Pierre-Sassoulas
Copy link
Member Author

I can cleanup the history and rebase if you want. I'm not sure if the current fail from the CI is due to my changes, so maybe rebasing would help ?

`tox.tox_env.errors.Fail: pass_env values cannot contain whitespace, use comma to have multiple values in a single line, invalid values found 'GH_RELEASE_NOTES_TOKEN GITHUB_REF GITHUB_REPOSITORY

@nicoddemus
Copy link
Member

I can cleanup the history and rebase if you want. I'm not sure if the current fail from the CI is due to my changes, so maybe rebasing would help ?

The failure will be fixed in #10578, once we merge that don't worry that we can rebase this PR. 👍

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Pierre-Sassoulas!

LGTM, great work! I will leave this up for a few more days in case anybody else wants to review it.

@nicoddemus
Copy link
Member

@Pierre-Sassoulas main has been fixed in #10578, could you please rebase or enable maintainers to push to your fork? I did rebase but could not push --force to your fork. 👍

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the avoid-truncation-when-truncating-means-longer-output branch from b3fddc4 to a5f6d75 Compare December 14, 2022 12:24
@Pierre-Sassoulas
Copy link
Member Author

Strange, "allow edit by maintainer" is checked. I rebased, I'm going to check the macos fail later today :)

@nicoddemus
Copy link
Member

I triggered the job again, and now it passed, so it seems like it was a flaky error, so do not worry.

@nicoddemus nicoddemus merged commit b31db48 into pytest-dev:main Dec 17, 2022
@Pierre-Sassoulas Pierre-Sassoulas deleted the avoid-truncation-when-truncating-means-longer-output branch December 17, 2022 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid truncation when it makes the output longer
2 participants