Answer the question
In order to leave comments, you need to log in
How to write unit tests for telnet in python?
Hello! I continue to comprehend python and came to the conclusion that tests - it really would probably be convenient with frequent rewriting / adding functions. But here's the question: I have, for example, some kind of microproject to automate some routine tasks ( https://github.com/sergkondr/noc_automate). It has methods for connecting to different devices via Telnet. How to test them? What would a test for such a method look like?
def _connect_to_juniper(self):
try:
telnet_instance = Telnet(self.host_IP, timeout=self.connection_timeout)
sleep(self.command_sleep)
telnet_instance.read_until(b'login: ')
telnet_instance.write(self.login)
telnet_instance.read_until(b'Password:')
telnet_instance.write(self.password)
telnet_instance.read_until(b'> ')
return telnet_instance
except:
print('%s (%s)\t- not available' % (self.host_IP, self.host_name))
print(NameError)
raise NameError('connection error')
Answer the question
In order to leave comments, you need to log in
telnet_instance = Telnet(self.host_IP, timeout=self.connection_timeout)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question