matthew at woodcraft.me.uk
Mon Sep 27 14:41:16 PDT 2010
Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> Matthew Woodcraft wrote:
>> But I think what I'd really like here is
>> for something like TestCase._formatMessage to be public: it seems to me
>> that pretty much anyone writing a custom TypeEqualityFunc is going to
>> want this facility, and it's bit of a shame to have to reimplement it.
> Ok - that's a reasonable request. Can you raise an issue for it?
I tried, but it won't let me without a 'Google account' :-(. Would it be
helpful if I put it in as a wishlist request on the Python tracker?
>> The other is unorderable_list_difference.
> That's in unittest in Python 2.7 - so I doubt it will be removed /
> moved. :-)
Excellent. Thank you for your quick response.
>> In this case, I think what I'd really like is a (variant of)
>> assertItemsEqual which always uses the form of output it chooses for
>> 'unsortable' items, as I find it's usually easier for me to read.
> I don't understand what you mean by this. What are you trying to compare
> and why is the output not good enough?
Here's an example:
a = [('b', (2, 3)), ('w', (3, 4))]
b = [('x', (2, 3)), ('w', (3, 4))]
Expected, but missing:
[('b', (2, 3))]
Unexpected, but present:
[('x', (2, 3))]
while the current assertItemsEqual gives
Sequences differ: [('b', (2, 3)), ('w', (3, 4))] != [('w', (3, 4)), ('x', (2, 3))]
First differing element 0:
('b', (2, 3))
('w', (3, 4))
- [('b', (2, 3)), ('w', (3, 4))]
+ [('w', (3, 4)), ('x', (2, 3))]
I find the first more convenient.
In general, I think that in assertItemsEqual, the 'first differing
element' bit (that has come from assertSequenceEqual) is as likely to be
misleading as it is to be helpful.
More information about the testing-in-python