testtools: Update to latest version.
[nivanova/samba-autobuild/.git] / lib / testtools / doc / for-test-authors.rst
index febbb84151b65423290b001d6c07884521098fdd..b83221bd5d0230b5f28bbbd3983b82e12241a259 100644 (file)
@@ -1322,6 +1322,27 @@ Safe attribute testing
 particular attribute.
 
 
+Nullary callables
+-----------------
+
+Sometimes you want to be able to pass around a function with the arguments
+already specified.  The normal way of doing this in Python is::
+
+  nullary = lambda: f(*args, **kwargs)
+  nullary()
+
+Which is mostly good enough, but loses a bit of debugging information.  If you
+take the ``repr()`` of ``nullary``, you're only told that it's a lambda, and
+you get none of the juicy meaning that you'd get from the ``repr()`` of ``f``.
+
+The solution is to use ``Nullary`` instead::
+
+  nullary = Nullary(f, *args, **kwargs)
+  nullary()
+
+Here, ``repr(nullary)`` will be the same as ``repr(f)``.
+
+
 .. _testrepository: https://launchpad.net/testrepository
 .. _Trial: http://twistedmatrix.com/documents/current/core/howto/testing.html
 .. _nose: http://somethingaboutorange.com/mrl/projects/nose/