Skip to main content

The new features in unittest for Python 2.7 backported to Python 2.4+.

Project description

unittest2 is a backport of the new features added to the unittest testing framework in Python 2.7. It is tested to run on Python 2.4 - 2.6.

To use unittest2 instead of unittest simply replace import unittest with import unittest2.

Classes in unittest2 derive from the equivalent 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. Similarly you can use the new assert methods on unittest2.TestCase with the standard unittest test running infrastructure. Not all of the new features in unittest2 will work with the standard unittest test loaders and runners however.

New features include:

  • addCleanups - better resource management

  • many new assert methods including better defaults for comparing lists, sets, dicts unicode strings etc and the ability to specify new default methods for comparing specific types

  • assertRaises as context manager, with access to the exception afterwards

  • test discovery and new command line options

  • test skipping and expected failures

  • load_tests protocol for loading tests from modules or packages

  • startTestRun and stopTestRun methods on TestResult

  • various other API improvements and fixes

Until I write proper documentation, the best information on all the new features is the development version of the Python documentation for Python 2.7:

There is some information about the new features in New and improved: new features in unittest.

Look for notes about features added or changed in Python 2.7.

unittest2 is maintained in an SVN repository courtesy of google code:

Differences

Differences between unittest2 and unittest in Python 2.7:

assertSameElements does not silence Py3k warnings as this uses warnings.catch_warnings() which is new in Python 2.6 (and is used as a context manager which would be a pain to make work with Python 2.4).

The underlying dictionary storing the type equality functions on TestCase is a custom object rather than a real dictionary. This allows TestCase instances to be deep-copyable on Python versions prior to 2.7.

TestCase.longMessage defaults to True because it is better. It defaults to False in Python 2.7 for backwards compatibility reasons.

python -m package doesn’t work until Python 2.7, to provide the command line features a unit2 (and unit2.py) script is provided instead.

CHANGELOG

0.1

Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unittest2-0.1.5.tar.gz (39.6 kB view details)

Uploaded Source

File details

Details for the file unittest2-0.1.5.tar.gz.

File metadata

  • Download URL: unittest2-0.1.5.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for unittest2-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b5fd97cb056fe739d4adfca831f2ba20e17d7ae61261c4d0bbdca3ffc196eba2
MD5 3b2b0259cae457eb5fcde85058af97df
BLAKE2b-256 829eceb8a2f887cd9198360a0c3c29ad5cab5a7237e6c1342f7fc4b43b00983e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page