| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Closes pytest-dev#8395 Co-authored-by: Antigravity <antigravity@google.com>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
@RonnyPfannschmidt I'm still waiting on your feedback :) |
Sorry, something went wrong.
There was a problem hiding this comment.
This. Technically looks good but is also at odds with a number of comments on the original issue
As such id like to defer to @nicoddemus
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @hamza-mobeen for the PR, overall great work!
I left some comments, please take a look.
Sorry, something went wrong.
| saved_config = util._config | ||
| util._config = config |
There was a problem hiding this comment.
Why is this necessary? Is the config being passed here different from the one already in util._config?
Sorry, something went wrong.
There was a problem hiding this comment.
Also, given this is the only place where util.assertrepr_compare is called, consider just passing the text diff style directly to util.assertrepr_compare.
Sorry, something went wrong.
| ) -> list[str]: | ||
| if ( | ||
| assertion_text_diff_style == ASSERTION_TEXT_DIFF_STYLE_BLOCK | ||
| and _is_multiline_text(left, right) |
There was a problem hiding this comment.
Not sure we should special case being multiline text or not; I think it is reasonable to always honor the block configuration, even for single line texts.
Sorry, something went wrong.
| right: str, | ||
| highlighter: _HighlightFunc, | ||
| verbose: int, | ||
| assertion_text_diff_style: str, |
There was a problem hiding this comment.
Instead of typing this as str, let's use Literal["ndiff", "block"]. This way we are more explicit, plus we can use match below.
Sorry, something went wrong.
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
for more information, see https://pre-commit.ci
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
There was a problem hiding this comment.
Thanks!
Sorry, something went wrong.
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
for more information, see https://pre-commit.ci
|
Hi, # Use a different formatting than the default.
left_repr = format(left)
right_repr = format(right)
if left_repr != right_repr:
highlighter = config.get_terminal_writer()._highlight
verbose = config.get_verbosity(Config.VERBOSITY_ASSERTIONS)
return ["", *_compare_eq_any(left_repr, right_repr, highlighter, verbose)] # missing argumentI know it's a bit of a minor issue, but please can you add default arguments that map to the previous version in the future: def _compare_eq_any(
left: object,
right: object,
highlighter: _HighlightFunc,
verbose: int,
assertion_text_diff_style: _AssertionTextDiffStyle = "ndiff", # added default argument
) -> Iterator[str]:I can add a PR to add this change, but I'd be interested if you have other thoughts. |
Sorry, something went wrong.
Add missing argument introduced in pytest-dev/pytest#14425
|
Private API is private for a reason. If you use it and it changes, that's on you and not on pytest. |
Sorry, something went wrong.
|
@George-Ogden do you require supporting old versions of pytest? If not, just require the latest one and update the call to pass the argument explicitly. Otherwise, one solution is to use different calls based on version, similar to pytest-dev/pytest-mock@1d42981. @The-Compiler is right, we don't provide any guarantee about private APIs, so plugins need to be aware that they might change during releases (even patch releases). Adding a new default value won't help much, because then 9.1.0 and 9.1.1 would still contain the old code, which can cause some confusion. |
Sorry, something went wrong.
|
@nicoddemus, thanks for your reply. I agree it's a bit late to add a default argument, and I've just changed the required pytest version for this plugin. It's not ideal to rely on a private API, but, for now, it's my best option for this use case. Hopefully, you can bear this in mind in the future, as I'm not the only person who relies on the internal API. A quick search for _compare_eq_any on GitHub turns up quite a lot of results. |
Sorry, something went wrong.
Sorry, something went wrong.
For what it's worth, most of those seem to be copies of pytest's source code (e.g. people accidentally comitting their virtualenvs). Searching for the import or ignoring pytest copies I see pytest-dbg, pytest-unordered (utapyngo/pytest-unordered#22), and maybe two standalone Python scripts which might be affected by this. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
closes #6757
Description
This PR introduces a new configuration option, assertion_text_diff_style, to allow users to customize how multiline string assertion failures are displayed.
As highlighted in #6757, when pytest uses ndiff to display differences for multiline strings (like output from capsys), it can sometimes become an unreadable "soup", especially when changes involve indentation or leading/trailing whitespace. The current behavior often results in a confusing line-by-line diff that is difficult to parse.
This PR adds an optional block diff style that displays the exact contents of the "Left" and "Right" text blocks intact and sequentially, making it significantly easier to read the literal multiline strings being compared without the interspersed ndiff noise.
Key changes:
Checklist