UnitTest Framework unittest2 is a backport of additional features added to the Python testing framework in Python 2.7 and onwards. Downloaded from the latest version https://pypi.python.org/pypi/unittest2
To use unittest2 instead of unittest, simply replace import unittest with import unittest2.
Classes in unittest2 derive from the appropriate classes in unittest, so it should be possible to use the unittest2 test running infrastructure without having to switch all your tests to using unittest2 immediately. In case you intend to implement new features, subclass your test case from unittest2.TestCase instead of unittest.TestCase
The following are the new features of UnitTest Framework unittest2 −
- addCleanups for better resource management
- Contains many new assert methods
- assertRaises as context manager, with access to the exception afterwards
- Has module level fixtures such as setUpModule and tearDownModule
- Includes load_tests protocol for loading tests from modules or packages
- startTestRun and stopTestRun methods on TestResult
In Python 2.7, you invoke the unit test command-line features (including test discover) with python -m unittest <args>.
Instead, unittest2 comes with a script unit2.
unit2 discover unit2 -v test_module
Next Topic – Click Here
Pingback: UnitTest Framework - Time Test - Adglob Infosystem Pvt Ltd