Pythons telnetlib unit tests
I am writing a simple program that talks to the router via telnet and issues some simple commands to it. I want to test these commands so that the program responds correctly to the servers and sends commands at the right time. However, I cannot figure out how to do this. The best I've come up with is to create a small telnet server for my unit tests, but that seems a bit over the top and I hope there will be an easier way to do this.
Does anyone have any idea?
source to share
The best practice in such cases is to mock the server object. Since you are using python 3, you can just use unittest.mock
to create a mock server object to use when testing. The docs are here: https://docs.python.org/3/library/unittest.mock.html
source to share