move api_server start and terminate to class method in order to start api_server only once

This commit is contained in:
httprunner
2017-06-20 14:22:52 +08:00
parent a95ff218c0
commit 502f2e4ef7
+12 -5
View File
@@ -8,19 +8,26 @@ class TestApiServer(unittest.TestCase):
""" """
Test case class that sets up an HTTP server which can be used within the tests Test case class that sets up an HTTP server which can be used within the tests
""" """
def setUp(self): @classmethod
super(TestApiServer, self).setUp() def setUpClass(cls):
self.api_server_process = multiprocessing.Process( cls.api_server_process = multiprocessing.Process(
target=api_server.app.run target=api_server.app.run
) )
self.api_server_process.start() cls.api_server_process.start()
time.sleep(0.1) time.sleep(0.1)
@classmethod
def tearDownClass(cls):
cls.api_server_process.terminate()
def setUp(self):
super(TestApiServer, self).setUp()
self.host = "http://127.0.0.1:5000" self.host = "http://127.0.0.1:5000"
self.api_client = requests.Session() self.api_client = requests.Session()
self.clear_users()
def tearDown(self): def tearDown(self):
super(TestApiServer, self).tearDown() super(TestApiServer, self).tearDown()
self.api_server_process.terminate()
def clear_users(self): def clear_users(self):
url = "%s/api/users" % self.host url = "%s/api/users" % self.host