Ensure function context is defined for async tests.

This fixes issue #419.