跳转到主要内容

简化从**BDD**或**功能**测试启动和终止Web开发服务器

项目描述

Test Live Server 已迁移至 Live and Let Die

https://pypi.python.org/pypi/liveandletdie https://github.com/peterhudec/liveandletdie

Live and Let Die 是一个简化从 BDD 或功能测试中启动和终止 Web 开发服务器的简单包。我为了 Authomatic 包的功能测试创建了它。

请注意,该包最近已从之前的 testliveserver 重命名为当前的 liveandletdie

该包目前支持 Google App engineDjangoFlaskwsgiref.simple_server。希望将来会添加对其他框架的支持。

用法

首先,您需要创建框架类的一个实例。

Django

import liveandletdie

# Django
app = liveandletdie.Django('path/to/django/project/',
                           host='0.0.0.0',
                           port=5555,
                           timeout=60.0)

Google App Engine

import liveandletdie

app = liveandletdie.GAE('path/to/dev_appserver.py',
                        'path/to/gae/app/dir', # containing app.yaml file
                        host='0.0.0.0',
                        port=5555,
                        timeout=60.0)

Flask

通过 Flask,您必须使用 liveandletdie.Flask.wrap(app) 包装 WSGI 应用程序

# flask/app/main.py
from flask import Flask

DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'

app = Flask(__name__)
app.config.from_object(__name__)

@app.route('/')
def home():
    return 'Hello World!'

if __name__ == '__main__':

    # This does nothing unless you run this module with --liveandletdie flag.
    import liveandletdie
    liveandletdie.Flask.wrap(app)

    app.run()
import liveandletdie

app = liveandletdie.Flask('path/to/flask/app/main.py',
                          host='0.0.0.0',
                          port=5555,
                          timeout=60.0)

Pyramid (wsgiref.simple_server)

通过 wsgiref.simple_server,您必须使用 liveandletdie.WsgirefSimpleServer.wrap(app) 包装 WSGI 应用程序

# pyramid/app/main.py
from wsgiref.simple_server import make_server

from pyramid.config import Configurator
from pyramid.response import Response


def home(request):
    return Response('Hello World!')


if __name__ == '__main__':

    config = Configurator()
    config.add_route('home', '/')
    config.add_view(home, route_name='home')
    app = config.make_wsgi_app()

    # This does nothing unless you run this module with --liveandletdie flag.
    import liveandletdie
    liveandletdie.WsgirefSimpleServer.wrap(app)

    server = make_server('127.0.0.1', 8080, app)
    server.serve_forever()
import liveandletdie

app = liveandletdie.Flask('path/to/pyramid/app/main.py',
                          host='0.0.0.0',
                          port=5555,
                          timeout=60.0)

使用 App 实例

所有支持的框架的接口都是相同的。

# Start the app.
# If kill is True, it will kill any Python process listening on port 5555
process = app.live(kill=True)

# You can check whether it is running
is_running = app.check()

# Stop it
app.die()

简单的单元测试示例:https://github.com/peterhudec/liveandletdie/blob/master/test_examples/unittest_example/tests.py

简单的 PyTest 示例:https://github.com/peterhudec/liveandletdie/blob/master/test_examples/pytest_example/tests.py

简单的 Lettuce 示例:https://github.com/peterhudec/liveandletdie/blob/master/test_examples/lettuce_example/tests.py

开发者

克隆

$ git clone https://github.com/peterhudec/liveandletdie.git

启动开发环境。这将在项目根目录中创建 ./venv 虚拟环境。

$ sh bootstrap.sh

运行测试

$ sh run-all.sh

享受吧!

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定该选择哪一个,请了解有关 安装包 的更多信息。

源分布

TestLiveServer-0.0.2.tar.gz (6.8 kB 查看哈希值)

上传时间

由以下支持

AWSAWS 云计算和安全赞助商 DatadogDatadog 监控 FastlyFastly CDN GoogleGoogle 下载分析 MicrosoftMicrosoft PSF 赞助商 PingdomPingdom 监控 SentrySentry 错误记录 StatusPageStatusPage 状态页面