如何 运行 服务器作为 py.test 的固定装置
How to run server as fixture for py.test
我想用服务器作为夹具编写 Selenium 测试:
import pytest
@pytest.fixture()
def driver(request):
from selenium import webdriver
d = webdriver.Firefox()
request.addfinalizer(d.close)
return d
@pytest.fixture()
def server():
from server import run
run(host="localhost", port=8080)
def test_can_see_echo(driver,server):
page = TestPage(driver)
page.fill_text_in_input("test")
page.click_send()
print page.get_returnet_value()
服务器装置中的函数 运行 是 bottle 运行 函数。问题是,当我调用 运行() 程序进入无限循环并且不执行测试主体时。我应该在同一个线程中调用 运行 吗?我的设计好吗?将来我想使用服务器夹具来集成到服务器状态。例如,使用 Selenium 进行测试 "add comment",最后使用服务器 fixture 询问服务器是否确实发生了此操作。
测试挂起,因为您的 run(host="localhost", port=8080)
启动了一个永远等待的服务器。您应该以不同的 thread/process.
启动该服务器
为 运行 外部服务器进程查看类似 pytest-xprocess 的内容以进行测试。
我想用服务器作为夹具编写 Selenium 测试:
import pytest
@pytest.fixture()
def driver(request):
from selenium import webdriver
d = webdriver.Firefox()
request.addfinalizer(d.close)
return d
@pytest.fixture()
def server():
from server import run
run(host="localhost", port=8080)
def test_can_see_echo(driver,server):
page = TestPage(driver)
page.fill_text_in_input("test")
page.click_send()
print page.get_returnet_value()
服务器装置中的函数 运行 是 bottle 运行 函数。问题是,当我调用 运行() 程序进入无限循环并且不执行测试主体时。我应该在同一个线程中调用 运行 吗?我的设计好吗?将来我想使用服务器夹具来集成到服务器状态。例如,使用 Selenium 进行测试 "add comment",最后使用服务器 fixture 询问服务器是否确实发生了此操作。
测试挂起,因为您的 run(host="localhost", port=8080)
启动了一个永远等待的服务器。您应该以不同的 thread/process.
为 运行 外部服务器进程查看类似 pytest-xprocess 的内容以进行测试。