diff options
Diffstat (limited to 'lib/testtools/doc/for-test-authors.rst')
-rw-r--r-- | lib/testtools/doc/for-test-authors.rst | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/testtools/doc/for-test-authors.rst b/lib/testtools/doc/for-test-authors.rst index febbb84151..b83221bd5d 100644 --- a/lib/testtools/doc/for-test-authors.rst +++ b/lib/testtools/doc/for-test-authors.rst @@ -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/ |