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
[RFC] assert: keep "where … and …" output in verbose mode #5933
Conversation
This is quite hacky/involved. |
/cc @darrenburns via https://github.com/darrenburns/pytest-clarity (#5931) |
Changing pytest-clarity to use
|
This would be really cool! I personally prefer this approach over the templating suggestion, but I guess it may break backwards compatibility since the hook interface will change? |
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.
I much prefer this approach over templating... hooks are kept backward compatible if we introduce new parameters, so let's go for it. 👍
@@ -472,7 +472,7 @@ def pytest_unconfigure(config): | |||
# ------------------------------------------------------------------------- | |||
|
|||
|
|||
def pytest_assertrepr_compare(config, op, left, right): | |||
def pytest_assertrepr_compare(config, op, left, right, expl): |
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.
Please update the docstring with expl
as well. 😁
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.
Would need more updating in general then, especially for when we go with the return-string-to-skip special postprocessing approach.
@@ -146,7 +148,7 @@ def assertrepr_compare(config, op, left, right): | |||
type_fn = (isdatacls, isattrs) | |||
explanation = _compare_eq_cls(left, right, verbose, type_fn) | |||
elif verbose > 0: | |||
explanation = _compare_eq_verbose(left, right) | |||
return expl + "\n~" + "\n~".join(_compare_eq_verbose(left, right)) |
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.
Sorry, I don't get the "\n~"
part...? 🤔
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.
It mimics https://github.com/blueyed/pytest/blob/1543a16330a5be10022505429b66608e7ee0ed19/src/_pytest/assertion/__init__.py#L139 (which is skipped for strings).
It's the "mini language" used with https://github.com/blueyed/pytest/blob/1543a16330a5be10022505429b66608e7ee0ed19/src/_pytest/assertion/util.py#L59-L91.
No, |
Why do you both prefer this over a special template var (keep in mind that you have to use the "mini template language" here already). |
Oh I didn't realize we had a template language in place, sorry for having given my opinion so soon. I will have to take a deeper look later then. |
TODO: - [ ] real plugin hook? - [ ] should handle other places where safeformat is used also, via args/options to the hook then likely. Ref: pytest-dev#3962 Ref: pytest-dev#5933
@nicoddemus (it is a long-standing regression, so it would be great to make some progress here) |
Who can we ping about this - being more into the assertion rewriting part of pytest? |
Sorry about the delay, I've been busy with other things. The problem that I have with the def y():
return [0, 1]
def test():
assert y() == [1, 2, 3, 4] For this test failure, the
So the I see two options:
I wouldn't even know where to start with 1), and 2) would require some hacking, like setting At first look 2) is ugly, but we might evaluate it under the light that we already are doing something similar by installing What if we set if util._reprcompare is not None:
util._reprcompare_expl = expl
try:
custom = util._reprcompare(ops[i], each_obj[i], each_obj[i + 1])
finally:
util._reprcompare_expl = None
if custom is not None:
return custom Again, while this is ugly, at least it is kept internal and won't introduce a parameter which we might regret later. What do you think? |
Yes.
How does that help plugins with using the default? |
Unless I'm misunderstanding, I thought the patch was about to fix "keep "where … and …" output in verbose mode" in the pytest core, not necessarily expose to plugins the new "expls" parameter. In my previous post, (Btw sorry for the delay, I am on vacation and now I'm trying to catch up with everything). |
@nicoddemus |
Is that the right issue number? 🤔 |
@blueyed does closing this mean no charge coming? |
@JBKahn I've closed all my open PRs for now. Feel free to pick it up, I might come back to it later myself, but just had to clean up things for myself. |
@nicoddemus any more thoughts on this one? We'd really like to be able to use the explanation in the rewrite |
Ref: #5932
Fixes: #5192