Turbogears2 和 py.test

发布于 2024-09-25 07:24:58 字数 410 浏览 7 评论 0原文

我将测试环境从 Nose 切换到 py.test 以测试 Turbogears2 Web 应用程序。

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

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

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

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

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

I'm switching our testing environment from Nose to py.test for testing a Turbogears2 web application.

Currently, when Nose runs it gathers information from a testing configuration file (test.ini) that holds all the testing variables the application needs. And it seems to do so in an automatic way (I'm simply running nosetests and everything gets loaded)

The problem relies in the inability for py.test to be pointed at the right INI configuration file so that I can get the app loaded with the variables I need.

Currently, the failing point is pylons.app_globals which is simply non-existent when running py.test (hence everything fails).

I have been through the Turbogears documentation but they only mention Nose/nosetests and nothing else.

Is there a way to be able to lead the application with the testing variables I rely upon with py.test ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-10-02 07:24:58

就 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 仅在足够早地看到它时才会运行此挂钩。

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

HTH。霍尔格

As far as py.test's part is concerned, you can implement something like this:

# 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

Such a conftest.py file should currently best live at your checkout root directory as py-1.3.4 will only run this hook if it sees it early enough.

I also looked a bit around TurboGears but didn't erasily found the mechanism how/which test.ini is actually loaded. I can update the answer if somebody can provide this information.

HTH. Holger

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文