What's with this DeprecationWarning ("callable is None")?
<p>I'm writing a module, and I'm using <code>unittest</code> to write unit tests alongside the actual code.</p>

<p>Sometimes (almost nondeterministically, it seems), a function like the following that doesn't explicity return a value, asserted with <code>self.assertRaises(mymodule.MyEmptyException, myfunc())</code> (where <code>self</code> refers to the subclass of <code>unittest.TestCase</code>) raises a mysterious <code>DeprecationWarning</code>.</p>

<p>Here's an example of such a function:</p>

<pre><code>def insertn(self, items, lidex):
    """( z y x -- z b y x )
    add a list of items to the stack at the given index"""
    iter(items)
    for idx, obj in enumerate(items):
        self.insert(lidex, obj)
        lidex += 1
</code></pre>

<p>Its corresponding unit test:</p>

<pre><code>def test_insertn_fail(self):
    """expect failure during multiple insertion"""
    self.assertRaises(mouse16.BadInternalCallException,
        stack.insertn([8, 4, 12], 16))
    with self.assertRaises(TypeError):
        stack.insertn(8, 16)
</code></pre>

<p>gives (for example):</p>

<pre><code>./mousetesting.py:103: DeprecationWarning: callable is None
</code></pre>

<p>I thought making the function have a non-<code>None</code> return value might fix the problem (i.e. <code>return 0</code>) but then I get (for example):</p>

<pre><code>======================================================================
ERROR: test_insertn_fail (__main__.CoreStack)
expect failure during multiple insertion
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./mousetesting.py", line 103, in test_insertn_fail
    stack.insertn([8, 4, 12], 16))
  File "/usr/lib/python3.5/unittest/case.py", line 727, in assertRaises
    return context.handle('assertRaises', args, kwargs)
  File "/usr/lib/python3.5/unittest/case.py", line 176, in handle
    callable_obj(*args, **kwargs)
TypeError: 'int' object is not callable

----------------------------------------------------------------------
</code></pre>

<p>So the <code>unittest</code> module is trying to call the return value of a function... but doesn't complain that <code>None</code> <em>also</em> isn't <code>callable</code>?</p>

<p>I don't really know enough about the internals of Python to understand what's going on here. I'd like to avoid having my tests break in a way I don't know how to fix in the future because of a <code>DeprecationWarning</code> I ignored.</p>

<p>Must my functions (but only some of them, and not all the time?) return a (memory-wasting) closure or meaningless lambda expression to avoid this? Or should I craft a thing that detects whether a test is in progress and <em>only then</em> return a no-op lambda? That seems like a lot of work just to avoid a <code>DeprecationWarning</code>.</p>