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=False
forpxssh.login()
then you cannot usepxssh.prompt()
. According to the doc:So for your code, both
prompt()
would time out and.before
would have all output and.after
would bepexpect.exceptions.TIMEOUT
.The doc also says that
but this is NOT true based on my testing:
From the result you can see
.before
is not erased for the 2ndprompt()
. Instead it's appended with the new output.