When testing code that modifies directories and files, it is useful to be able
to create and inspect a sample tree of directories and files easily. The
tl.testing.fs module provides support for creating a tree from a textual
description, listing it in the same format and clean up after itself.

In a doc test, these facilities might be used like this to create and list a
directory, a file and a symbolic link:

Some functionality one might want to test makes use of external programs such
as a pager or a text editor. The tl.testing.script module provides
utilities that install simple mock scripts in places where the code to be
tested will find them. They take a string of Python code and create a wrapper
script that sets the Python path to match that of the test and runs the code.

While it is straight-forward to compare the content of two cairo surfaces
in Python code, handling graphics is beyond doc tests. However, the manuel
package can be used to extract more general test cases from a text document
while allowing to mix them with doc tests in a natural way.

The tl.testing.cairo module provides a test suite factory that uses manuel
to execute graphical tests formulated as restructured-text figures. The
caption of such a figure is supposed to be a literal Python expression whose
value is a cairo surface, and its image is used as the test expectation.

This is how a surface might be compared to an expected image in a doc test:

The standard TestCase class doesn’t collect errors and failures that
occurred in other threads than the main one. The tl.testing.thread module
provides thread classes and a ThreadAwareTestCase class to allow just
that, as well as some other conveniences for tests that deal with threads:
preventing expected unhandled exceptions in threads from being printed with
the test output, reporting threads left behind by a test, running code in a
daemon thread, joining threads and counting the threads started during the
test’s run time:

As manuel provides some powerful features in addition to standard
doctests, manuel test suites are set up slightly differently from standard
ones. The tl.testing.doctest module implements a DocFileSuite factory
that can be used like the standard one but creates a test suite using manuel
and allows some additional configuration related to manuel, among them the
ability to interpret footnotes that used to be done using the deprecated
zope.testing.doctest: