我需要测试我的服务器的可用性。我已经写了测试:
class TestApp(unittest.TestCase):
def setUp(self):
self.child_pid = os.fork()
if self.child_pid == 0:
HTTPServer(('localhost', 8000), Handler).serve_forever()
def test_app(self):
try:
urllib.request.urlopen('http://localhost:8000')
except (URLError, HTTPError) as e:
self.fail()但是在测试通过之后,init采用了几个python进程。测试结束后如何杀除子进程?
发布于 2020-02-20 04:25:24
找到解决方案了。需要使用threading模块:
class TestApp(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.server = ...
thread = threading.Thread(target=cls.server.serve_forever)
thread.start()
@classmethod
def tearDownClass(cls):
cls.server.shutdown()https://stackoverflow.com/questions/60304636
复制相似问题