gpt4 book ai didi

python - Turbogears2 和 py.test

转载 作者:行者123 更新时间:2023-11-28 21:34:42 25 4
gpt4 key购买 nike

我正在将我们的测试环境从 Nose 切换到 py.test 以测试 Turbogears2 网络应用程序。

目前,当 Nose 运行时,它会从一个测试配置文件 (test.ini) 中收集信息,该文件包含应用程序所需的所有测试变量。而且它似乎以自动方式执行此操作(我只是运行 nosetests 并且所有内容都已加载)

问题在于无法将 py.test 指向正确的 INI 配置文件,这样我就可以让应用程序加载我需要的变量。

目前,失败点是 pylons.app_globals,它在运行 py.test 时根本不存在(因此一切都失败)。

我已经阅读了 Turbogears 文档,但他们只提到了 Nose/nosetests,没有其他任何内容。

有没有办法能够使用我依赖的测试变量来引导应用程序 py.test ?

最佳答案

就 py.test 的部分而言,你可以实现这样的东西:

# content of conftest.py
def pytest_sessionstart():
# setup resources before any test is executed

def pytest_sessionfinish():
# teardown resources after the last test has executed

这样的 conftest.py 文件目前最好保存在您的结帐根目录中,因为 py-1.3.4 只会在足够早的时候运行此 Hook 。

我也仔细查看了 TurboGears,但没有轻易找到实际加载 test.ini 的机制。如果有人可以提供此信息,我可以更新答案。

HTH。霍尔格

关于python - Turbogears2 和 py.test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3835078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com