Jac*_*son 5 python integration-testing pytest tox
我正在使用Tox来检查我正在开发的系统在安装在新环境中时表现良好(+完整性检查setup.py文件).但是,系统使用memcached服务器,理想情况下我想为每次Tox运行生成一个新服务器.
是否有一种首选的方法在运行测试之前启动程序(之后关闭它们)或者我是否需要编写自定义运行程序?
编辑:测试运行器是py.test
详细说明flub对py.test使用其夹具机制的最佳方法的评论.使用此内容创建conftest.py文件:
# content of conftest.py
import pytest, subprocess
@pytest.fixture(scope="session", autouse=True)
def startmemcache(request):
proc = subprocess.Popen(...)
request.addfinalizer(proc.kill)
Run Code Online (Sandbox Code Playgroud)
"autouse"标志意味着将为每次测试运行激活此灯具,而无需任何测试参考.但是,实际上,您可能希望将测试的子进程的连接详细信息用于测试,这样您就不必使用魔术端口号.你不会使用"autouse",而是返回一个夹具对象来连接到memcache,很好地将测试配置封装在一个地方(夹具功能).有关更多示例,请参阅文档.
这确实不是 的任务tox。我的建议是您在使用的实际单元测试setup框架(、、、...)的函数/方法py.test中执行此操作。noseunitteststox
原发帖者评论:
pytest_configure这pytest_unconfigure是conftest.py一个产生/终止的好地方。