Index: lldb/packages/Python/lldbsuite/test/lldbpexpect.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -53,11 +53,12 @@
 
     def expect(self, cmd, substrs=None):
         self.assertNotIn('\n', cmd)
-        self.child.sendline(cmd)
         # If 'substrs' is a string then this code would just check that every
         # character of the string is in the output.
         assert not isinstance(substrs, six.string_types), \
             "substrs must be a collection of strings"
+
+        self.child.sendline(cmd)
         if substrs is not None:
             for s in substrs:
                 self.child.expect_exact(s)
Index: lldb/test/API/test_utils/TestPExpectTest.py
===================================================================
--- lldb/test/API/test_utils/TestPExpectTest.py
+++ lldb/test/API/test_utils/TestPExpectTest.py
@@ -2,14 +2,9 @@
 Test the PExpectTest test functions.
 """
 
+from lldbsuite.test.lldbpexpect import *
 
-import lldb
-import lldbsuite.test.lldbutil as lldbutil
-from lldbsuite.test.lldbtest import *
-from textwrap import dedent
-
-
-class TestPExpectTestCase(TestBase):
+class TestPExpectTestCase(PExpectTest):
 
     mydir = TestBase.compute_mydir(__file__)
     NO_DEBUG_INFO_TESTCASE = True