ilogue/fexpect — pull request #11 by jladdjr (2013-05-16 01:49:17+00:00)
Title: Support for calling run/sudo/local both inside and outside 'with expecting(..)' block.

Currently, if you call run() outside of a 'with expecting(..)' block, you get a traceback that says that fabric.state.env.expectations hasn't been defined. This is happening because fexpect wraps *every* command it receives with 'expect code' which depends on expectations being set. Commands should only be wrapped if they are called inside of a 'with expecting(..) block.'

This patch adds some conditional logic to api.py to determine whether or not to wrap a command with 'expect code' before invoking fabric's run/sudo/local methods. It also provides a test demonstrating the ability to call run both inside and outside of a 'with expecting(..)' block.

This patch should address the issue mentioned by jberryman here:
https://github.com/ilogue/fexpect/issues/8