unittest2
The new features in unittest backported to Python 2.4+.
What it is and what it does
unittest2 is a backport of unittest improvements introduced in Python 2.7 and later versions, designed to run on older Python releases. It provides a drop-in replacement for the standard unittest module by allowing you to import unittest2 instead of unittest, giving access to modern testing features on legacy Python versions.
The package includes enhancements such as additional assert methods with better comparison defaults, assertRaises as a context manager, test discovery, class and module-level fixtures (setUpClass, tearDownClass, setUpModule, tearDownModule), test skipping, and improved command-line tools via the unit2 script. It has no runtime dependencies and installs as a pure Python wheel.
Use it for:
- Maintaining test suites on Python 2.6 systems that need modern assertion methods without upgrading the Python version.
- Running test discovery on legacy Python versions before 2.7 introduced the feature natively.
- Using assertRaises as a context manager on Python 2.6 codebases.
- Accessing class-level and module-level test fixtures on older Python releases.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Backports unittest features from Python 2.7 and later versions to earlier Python releases, allowing use of modern testing assertions and test discovery on older Python versions.
No. The package has been abandoned since 2015 and targets Python versions that reached end-of-life over a decade ago. Modern Python includes all these features natively. Install only if you are maintaining a legacy codebase stuck on Python 2.6 or earlier that cannot be upgraded; otherwise, use the standard unittest module.
Install
unittest2 on PyPI
pip
pip install unittest2uv
uv add unittest2poetry
poetry add unittest2Installing unittest2
Before you install
Installation is straightforward with no runtime dependencies. However, the package has been abandoned since 2015 and is no longer maintained.
License in practice
Licensed under BSD (permissive), so there are no restrictions on use in proprietary or open-source projects.
Quickstart
pip install unittest2
import unittest2
class TestExample(unittest2.TestCase):
def test_something(self):
self.assertEqual(1, 1)
Targets Python 2.4, 2.5, 2.6, 2.7, 3.2, 3.3, 3.4 and pypy; modern Python versions include these features natively.
Verify before relying
- Whether unittest2 remains compatible with modern Python tooling and CI/CD systems despite its age.
- Current state of the mercurial repository and whether it is still accessible or archived.
Package facts
| License | UNKNOWN (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 4,063 days since the last release |
| First released | |
| Downloads | 1,292,386/month — #4,101 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: unittest2-1.1.0-py2.py3-none-any.whl
Keywords: unittest, testing, tests
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
traceback2Provides a backport of Python's traceback…
permissive · top 5,000 on PyPI
configparser2Backport of Python 3's configparser module to…
permissive · top 15,000 on PyPI
multiprocessingBackport of Python 2.6/3.0 multiprocessing to…
permissive · top 15,000 on PyPI
backports.tempfileProvides the TemporaryDirectory context manager…
permissive · top 5,000 on PyPI
testtoolstesttools extends Python's standard unittest…
permissive · top 5,000 on PyPI
nose2nose2 is a test runner that extends Python's…
permissive · top 15,000 on PyPI
linecache2Provides a backport of Python's linecache…
permissive · top 5,000 on PyPI
functools32Backport of Python 3.2's functools module…
permissive · top 15,000 on PyPI
inspect2Provides the Python 3.6 inspect module API on…
permissive · top 15,000 on PyPI