我整个星期都在四处寻找,无法解决如何让我们的pylons服务器实例开始与Behave BDD一起使用。你们中的任何人都可以给我一个例子或提供你自己的例子吗?以下是我正在使用的内容:
在Behave doc网站的Tutorial页面上,启动一个简单的服务器并使用selenium,这是他们的Behave功能/ environment.py的示例代码:
import threading
from wsgiref import simple_server
from selenium import webdriver
from my_application import model
from my_application import web_app
def before_all(context):
context.server = simple_server.WSGIServer(('', 8000))
context.server.set_app(web_app.main(environment='test'))
context.thread = threading.Thread(target=context.server.serve_forever)
context.thread.start()
context.browser = webdriver.Chrome()
def after_all(context):
context.server.shutdown()
context.thread.join()
context.browser.quit()
def before_feature(context, feature):
model.init(environment='test')
这是一个开始,但我不知道如何将这种方式与我们的'pylowiki'味道的启动方式结合起来。我发现另一个例子可能提供更好的线索,它是here。在这个例子中,我假设我用“context”替换“world”,但除此之外,在这个例子中启动服务器的方式与我们自己的environment.py启动方式不同。 我认为最后一件事可能是方便的是包含我们当前环境设置中的代码:
pylowiki /配置/ environment.py
# -*- coding: utf-8 -*-
"""Pylons environment configuration"""
import os
from mako.lookup import TemplateLookup
from pylons import config
from pylons.error import handle_mako_error
from sqlalchemy import engine_from_config
import pylowiki.lib.app_globals as app_globals
import pylowiki.lib.helpers
from pylowiki.config.routing import make_map
from pylowiki.model import init_model
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
object
"""
# Pylons paths
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = dict(root=root,
controllers=os.path.join(root, 'controllers'),
static_files=os.path.join(root, 'public'),
templates=[os.path.join(root, 'templates')])
# Initialize config with the basic options
config.init_app(global_conf, app_conf, package='pylowiki', paths=paths)
config['routes.map'] = make_map()
config['pylons.app_globals'] = app_globals.Globals()
config['pylons.h'] = pylowiki.lib.helpers
# Create the Mako TemplateLookup, with the default auto-escaping
config['pylons.app_globals'].mako_lookup = TemplateLookup(
directories=paths['templates'],
error_handler=handle_mako_error,
module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
input_encoding='utf-8', output_encoding='utf-8', default_filters=['escape'],
imports=['from webhelpers.html import escape'])
# Setup the SQLAlchemy database engine
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)
答案 0 :(得分:0)
文档说明您至少需要在feature文件夹中使用environment.py,并逐步添加文件夹
https://behave.readthedocs.io/en/latest/gherkin.html#controlling-your-test-run-with-tags