-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
approx
representation of details failed when using a ApproxSequenceLike
which is not list
or tuple
#11797
Comments
I digged into it a bit. elif (
hasattr(expected, "__getitem__")
and isinstance(expected, Sized)
# Type ignored because the error is wrong -- not unreachable.
and not isinstance(expected, STRING_TYPES) # type: ignore[unreachable]
):
cls = ApproxSequenceLike When generating the detailed output the if isinstance(x, (list, tuple)):
seq_type = type(x)
return seq_type(_recursive_sequence_map(f, xi) for xi in x)
else:
return f(x) This |
Replacing def _recursive_sequence_map(f, x):
"""Recursively map a function over a sequence of arbitrary depth"""
if (
hasattr(x, "__getitem__")
and isinstance(x, Sized)
# Type ignored because the error is wrong -- not unreachable.
and not isinstance(x, STRING_TYPES) # type: ignore[unreachable]
):
if isinstance(x, (list, tuple)):
seq_type = type(x)
else:
seq_type = list
return seq_type(_recursive_sequence_map(f, xi) for xi in x)
else:
return f(x) would result in
|
Approx is not general,the support for lists as is, is already a stretch Custom collection objects are not easily supportable |
Hi @RonnyPfannschmidt, I see your point and I'm of course totally fine with not changing code for a stretch use case! We would then just implement our own On the other hand, If applying such a change would be considered, I would be happy to work on a proper MR. |
I need to do a little digging today,but it seems like a Good idea, I'll try to get it together soon |
i'm slightly hesitant to transform any custom collection into a list that being said, the rep traceback shouldn't happen as well, i'll try to figure the exact exception |
i have a error indicating reproducer i'll extract a is_sequencelike and use that |
this needs a validation as it allows partially implemented sequences
this needs a validation as it allows partially implemented sequences
this needs a validation as it allows partially implemented sequences
…prox-sequence-like fix #11797: be more lenient on SequenceLike approx
this needs a validation as it allows partially implemented sequences
Description
When using a custom sequence like type then the comparison of
pytest.approx
works as expected if the assert isTrue
. But in case the assertion fails, the detailed output of what went wrong is broken.Given the following example:
The first assert statement is fine, as expected.
In the second assert fails, as expected.
But I get this output:
Setup
Also happens with pytest version 7.1.2 and 7.1.3
OS is Ubuntu 22.04
The text was updated successfully, but these errors were encountered: