[issue10273] Clean-up Unittest API

Raymond Hettinger report at bugs.python.org
Thu Nov 4 02:25:45 CET 2010

Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

> For the regexp methods we should use assertRegexp 

assertRegex is better.  it matches the name used in other unittest implementations, there is not confusion with camel casing RegExp vs Regexp, and it matches the former name of Python's own regex module.

> We should leave the gt / le / lt methods as they are. 

The assertLessEqual name is non-standard, it will never be spelled right by someone who hasn't used it recently.

> The documentation can be improved by moving *all* the deprecated 
> methods (new and old) out of the main documentation and
> into a separate section at the end of the documentation

See issue 10242 for a suggestion on how to handle renaming (document the new and old name in the same entry, noting that one name is old).

>> For assertItemsEqual Raymond suggests assertElementCountsEqual. 
> Why replace a long awkward name with an even longer 
> and more awkward name?

If length is an issue, assertCountsEqual will also do fine.  The important virtue is clarity.  The problem with ItemsEqual is that it doesn't tell you anything about what it does (unordered comparison where duplicates matter).  Also, the term "items" in Python usually means key/value pairs.  That is why we use the term "elements" in sets, itertools, etc.  In contrast, assertCountsEqual tells you what it does, compares the element counts.  It is the same as Counter(a)==Counter(b) for hashable elements and an equivalent for unhashable elements.


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list