Python Lambdas and Variable Bindings
<p>I've been working on a basic testing framework for an automated build.  The piece of code below represents a simple test of communication between two machines using different programs.  Before I actually do any tests, I want to completely define them - so this test below is not actually run until after all the tests have been declared.  This piece of code is simply a declaration of a test.</p>

<pre><code>remoteTests = []
for client in clients:
    t = Test(
        name = 'Test ' + str(host) + ' =&gt; ' + str(client),
        cmds = [
            host.start(CMD1),
            client.start(CMD2),

            host.wait(5),

            host.stop(CMD1),
            client.stop(CMD2),
        ],
        passIf = lambda : client.returncode(CMD2) == 0
    )
remoteTests.append(t)
</code></pre>

<p>Anyhow, after the test is run, it runs the function defined by 'passIf'.  Since I want to run this test for multiple clients, I'm iterating them and defining a test for each - no big deal.  However, after running the test on the first client, the 'passIf' evaluates on the last one in the clients list, not the 'client' at the time of the lambda declaration.</p>

<p>My question, then: when does python bind variable references in lambdas?  I figured if using a variable from outside the lambda was not legal, the interpretor would have no idea what I was talking about.  Instead, it silently bound to the instance of the last 'client'.</p>

<p>Also, is there a way to force the resolution the way I intended it?</p>
