testing-cabal / unittest-ext

Automatically exported from code.google.com/p/unittest-ext
2 stars 2 forks source link

Idea: support assertItemsUnique #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There are many times that I want to check that all items are unique in a list.
I think that unittest should provide assertItemsUnique.
Please try to consider it.

Test Code:
    def test_is_ipv4(self):
        valid_patterns = ("0.0.0.0",
                          "255.255.255.255",
                          "1.2.3.4",
                          "255.255.255.255")
        self.assertItemsUnique(valid_patterns)        
        for valid_pattern in valid_patterns:
            self.assertIsTrue(is_ipv4(valid_pattern))

Output:
        self.assertItemsUnique(valid_patterns)
AssertionError: Sequence has the same items:

First Same element: 1
...

Original issue reported on code.google.com by msm...@gmail.com on 10 Nov 2013 at 1:11

GoogleCodeExporter commented 9 years ago
Why not just use self.assertEqual(len(valid_patterns), 
len(set(valid_patterns))) or similar?

Original comment by fuzzyman on 14 Nov 2013 at 11:21

GoogleCodeExporter commented 9 years ago
Because I need more details about the error.

    self.assertEqual(len(valid_patterns), len(set(valid_patterns)))
AssertionError: 976 != 975

I think that the above error message is of little use.

Original comment by msm...@gmail.com on 15 Nov 2013 at 10:41

GoogleCodeExporter commented 9 years ago
self.assertCountEqual(set(valid_pattterns), valid_patterns) - this will tell 
you if the collections have different members and should give you a useful 
error message.

Original comment by fuzzyman on 15 Nov 2013 at 12:34

GoogleCodeExporter commented 9 years ago
This is a reasonable request - can I point you at cPython's bugtracker itself 
though: unittest2 is now focused on backports. Non-backport standard things 
will go into cPython first. Experimental things will be done in other projects 
e.g. testtools.

Original comment by robert.c...@gmail.com on 4 Nov 2014 at 2:59