Project:Python/Tests

This page lists tips and good practices for handling test suites in Python packages.

Test suites
The following table lists the packages installing common test suites, their module names and packages installing them.

unittest and unittest2
unittest is Python's built-in test suite module. This module is constantly developed and new features are added in every version of Python. Especially, Python 2.7/3.2 have seen many improvements that a number of packages rely on.

unittest2 aims to be a backport of those new features to the older Python versions. In this common case, the affected packages use either unittest2 or unittest conditionally, similarly to the following snippet:

Common conditional import of unittest2

In this case, the developer is responsible for assuring which Python versions require unittest2, and which work fine with plain unittest. Often, requiring as an unconditional dependency is unnecessary.

In Gentoo, we consider three cases:


 * 1) if tests work fine with plain unittest in all supported implementations, no dependency is used,
 * 2) if tests work fine with the default PYTHON_TARGETS but older implementations supported by the package require unittest2, dependency on  is used,
 * 3) if tests require unittest2 with the default PYTHON_TARGETS, dependency on  is used.

In the two latter cases, plain [${PYTHON_USEDEP}] is appropriate.