from pexpect import pxssh
import getpass
import time
import sys
s=pxssh.pxssh()
class Testinstall:
def setup_class(cls):
cls.s=pxssh.pxssh()
cls.s.login('10.10.62.253', 'User','PW',auto_prompt_reset=False)
def teardown_class(cls):
cls.s.logout()
def test_cleanup(cls):
cls.s.sendline('cat test.py')
cls.s.prompt(timeout=10)
cls.s.sendline('cat profiles.conf')
cls.s.prompt(timeout=10)
print('s.before')
print (cls.s.before)
print('s.after')
print(cls.s.after)
In above code print(cls.s.before) prints, output of both cat commands.
As per expectation it should only print output of the 2nd cat command i.e cat profiles.conf.
When tried in python session in shell it shows output of only second cat command ( as per expectation)
If you use
auto_prompt_reset=Falseforpxssh.login()then you cannot usepxssh.prompt(). According to the doc:So for your code, both
prompt()would time out and.beforewould have all output and.afterwould bepexpect.exceptions.TIMEOUT.The doc also says that
but this is NOT true based on my testing:
From the result you can see
.beforeis not erased for the 2ndprompt(). Instead it's appended with the new output.