Ok, after realising with the help of @Alo Sarv that the problem lied in the multiprocessing module, I found a solution.
Here it is in case someone encounters the same problem:
file 1:testServer.py
import SocketServer
import SimpleHTTPServer
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
f = self.wfile
self.send_response(200)
self.end_headers()
f.write("ok")
def runServer(port):
Handler = ServerHandler
httpd = SocketServer.TCPServer(("", port), Handler)
httpd.serve_forever()
if __name__ == "__main__":
runServer(8000)
file 2: test_testServer.py
from testServer import ServerHandler
import SocketServer
from threading import Thread
import httplib
import unittest
class serverThread(Thread):
def __init__(self, port):
self.Handler = ServerHandler
self.httpd = SocketServer.TCPServer(("", port), self.Handler)
Thread.__init__(self)
def run(self):
self.httpd.serve_forever()
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.serverThread = serverThread(8000)
cls.serverThread.daemon = True
cls.serverThread.start()
@classmethod
def tearDownClass(cls):
cls.serverThread.httpd.__shutdown_request = True
def test_Server(self):
conn = httplib.HTTPConnection("localhost", 8000)
conn.request("GET", "")
response = conn.getresponse().read()
self.assertTrue(response, "ok")
if __name__ == "__main__":
unittest.main()
In short, the solution was to replace the use of multiprocessing by the use of threads. Then, adapting the server in order to be able to stop the thread properly (because thread can not be killed as easily as Process)