How to start telnet server and run a test?

Hi all, wrote a script to connect to telnet, I want to test it but there is one problem, the test I wrote, but the test stops setUpClass and then does nothing, here is the test code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import SocketServer
from argparse import Namespace
from telnetsrv.threaded import TelnetHandler, command

from app.telnet import telnet

def args(cmd, host='localhost', user='a', password='a', port=10023):
 return Namespace(host=host, user=user, password=password, cmd=cmd, port=port)

class TelnetServer(SocketServer.TCPServer):
 allow_reuse_address = True

class MyHandler(TelnetHandler):
@command('version')
 def version(self, params):
self.writeresponse("V1.0")

 authNeedUser = True
 authNeedPass = True

 def authCallback(self, username, password):
 if user_name != the "a" or password != 'a':
 raise runtime error('Wrong password!')

class TelnetTest(unittest.TestCase):

@classmethod
 def setUpClass(cls):
 cls.server = TelnetServer (('localhost', 10023), MyHandler)
try:
cls.server.serve_forever()
 except KeyboardInterrupt:
 print("Exiting telnet server")

@classmethod
 def tearDownClass(cls):
cls.server.close()

 def test_telnet(self):
 res = telnet(args("version"))
 print( res.run() )
 self.assertEqual(1, 1)

if __name__ == "__main__":
 unittest.main()

as you can see I first want to understand the server and then run the test, it must be done in a single test
ie the problem is this, I run the test it creates the server and everything and hangs if you try to make a connection to the server from another terminal, everything is OK, but how to make it all in one script?, I tried to do so
threading.Thread(target=cls.server.serve_forever).start()

ie to run in a separate thread, but no result, I ask is not very to blame as the Python began to study not so long ago)))
June 10th 19 at 15:00
0 answer

Find more questions by tags Modular testingTelnetTesting softwarePython