Fix issue with intermittent test failures in test_pkg.py

The test failures were a result of randomized test order and the way
in which these tests were setting up mocks for pexpect.spawn.expect
and pexpect.spawn.match.

The code now mocks pexpect.spawn and then sets return values and match
in each test as appropriate. Code in setUp establishes a patch and a
cleanUp function is added to reverse the patch. No code is required in
tearDown as a result.

execute() was being Mocked using code in setUp and tearDown and this
was replaced that with a similar patch in setUp with a corresponding
cleanUp function to reverse its effects.

Since we're close to Juno, I've not gone down the path of converting
this test to use a fixture which would further reduce duplicated code.

Change-Id: I3edfd499823f2c2f4591e709384a24f1b55abe5a
Closes-Bug: 1365531
Merge "Fix issue with intermittent test failures in test_pkg.py"