Replies: 9 comments 1 reply
-
Hi @jayvdb! Do you mean the output when an assertion fails? |
Beta Was this translation helpful? Give feedback.
-
No. I mean this TypeError is preventing usage on Mappings where they were supported by |
Beta Was this translation helpful? Give feedback.
-
With
This code just serves the purpose of making
|
Beta Was this translation helpful? Give feedback.
-
Right. That is a common misconception on what should happen with mappings. c.f. https://bugs.python.org/issue40909 If you want to force people to use the more explicit Alternatively, pytest-unordered could do what unittest should do and check the .keys first and then then check the .values. Ideally recursively. (which appears to be wontfix for unittest: https://bugs.python.org/issue36201) |
Beta Was this translation helpful? Give feedback.
-
@jayvdb could you please provide a real-world example where recursive behaviour is required? |
Beta Was this translation helpful? Give feedback.
-
I have a structure that looks like:
During test execution I compare against a similar structure, but I don't care about the order of
This is certainly much cleaner than the alternative, but it would be nice to have a call that handles that for you. I could imagine a deeper nested structure that needs further recursive handling. |
Beta Was this translation helpful? Give feedback.
-
@rpocase: I would just use the following code instead:
|
Beta Was this translation helpful? Give feedback.
-
@utapyngo That's definitely a lot better than my example. The only other use case I can think of is just a convenience. E.g., building assertions based on recording live results could save some minor data set clean up when integrating the results. Implicit conversions could also be unsafe/unexpected, making interface extensions a must. Overall, I'm fairly convinced this likely isn't worth the effort without a much broader example. |
Beta Was this translation helpful? Give feedback.
-
It is usually better to explicitly mark unordered collections after recording live results. |
Beta Was this translation helpful? Give feedback.
-
unittest.TestCase.assertCountEqual
supported mappings.This is especially useful for comparing two json objects. It can be implemented by first checking the keys of both are 'unsorted equal', and then deeply checking each of the keys values.
Beta Was this translation helpful? Give feedback.
All reactions