python怎么启动服务器_如何在Python单元中从命令行启动服务器

我正在为一个Python脚本构建一个测试程序,该脚本将与rejectdb数据库一起执行工作。作为setUp()方法的一部分,我试图让测试人员在端口28016上的localhost上启动RejectDB服务器,以防尚未启动。在

我用subprocess启动服务器。问题是,根据https://docs.python.org/2/library/subprocess.html,subprocess等待命令完成。在这种情况下,似乎只要服务器启动并运行,过程就不完整,测试也不会继续超过setUp()阶段。在

下面是我尝试的脚本:import unittest

import rethinkdb as r

import subprocess

class TestController(unittest.TestCase):

HOST = "localhost"

PORT_OFFSET = 1

PORT = 28015 + PORT_OFFSET

DB = "ipercron"

TABLE = "sensor_data"

def setUp(self):

try:

self.conn = r.connect(self.HOST, self.PORT)

except r.ReqlDriverError:

print("The RethinkDB server is not yet ready. Starting it up...")

subprocess.call(["rethinkdb", "--port-offset", str(TestController.PORT_OFFSET)])

self.conn = r.connect(self.HOST, self.PORT)

if TestController.DB not in r.db_list().run(self.conn):

r.db_create(TestController.DB).run(self.conn)

self.conn.use(TestController.DB)

if TestController.TABLE not in r.table_list().run(self.conn):

r.table_create(TestController.TABLE).run(self.conn) # Create the table if it does not yet exist

r.table(TestController.TABLE).delete().run(self.conn) # Empty the table to start with a clean slate

def test_upper(self):

self.assertEqual('foo'.upper(), 'FOO')

suite = unittest.TestLoader().loadTestsFromTestCase(TestController)

unittest.TextTestRunner(verbosity=2).run(suite)

subprocess用于在命令行执行rethinkdb --port-offset 1命令,然后继续执行脚本。但是,当我运行脚本时,会收到一条通常的消息:服务器已就绪:

^{pr2}$

没有任何进一步的行动。如何让unittest继续进行测试?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值