What is the difference between Python's unittest and unittest2 modules?

Anton Daneyko picture Anton Daneyko · Jan 18, 2016 · Viewed 7.1k times · Source

I currently work on some code that uses unittest2 module. I suspect this code was meant for the python2. Can one use python3 unittest as a drop in replacement for unittest2? What is the difference between the two?

Answer

rbp picture rbp · Jan 18, 2016

According to the Python 2.7 unittest docs:

unittest2: A backport of new unittest features for Python 2.4-2.6 Many new features were added to unittest in Python 2.7, including test discovery. unittest2 allows you to use these features with earlier versions of Python.

So moving from unittest2 under Python 2 to unittest under Python 2.7 or Python 3 should do exactly what you want