I need to start a server on localhost:3000
when starting python TestCase
and then close it after TestCase
finished.
I just realized that http.server
does not detach the server so after starting the server, the TestCase
does not continue until the server is not stopped.
class ServerTest(TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.server = socketserver.TCPServer(("", 3000), handler)
cls.server.serve_forever()
super().setUpClass()
... TESTS THAT SEND REQUESTS TO localhost:3000 ...
@classmethod
def tearDownClass(cls) -> None:
cls.server.server_close()
Is it possible to make it work with http.server
?