简体   繁体   English

Turbogears2和py.test

[英]Turbogears2 and py.test

I'm switching our testing environment from Nose to py.test for testing a Turbogears2 web application. 我将我们的测试环境从Nose切换到py.test以测试Turbogears2 Web应用程序。

Currently, when Nose runs it gathers information from a testing configuration file (test.ini) that holds all the testing variables the application needs. 当前,当Nose运行时,它将从测试配置文件(test.ini)收集信息,该文件包含应用程序所需的所有测试变量。 And it seems to do so in an automatic way (I'm simply running nosetests and everything gets loaded) 它似乎以一种自动方式进行(我只是在运行“ nosetests ,一切都被加载了)

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. 问题在于无法将py.test指向正确的INI配置文件,以便我可以将所需的变量加载到应用程序中。

Currently, the failing point is pylons.app_globals which is simply non-existent when running py.test (hence everything fails). 当前,失败点是pylons.app_globals,它在运行py.test时根本不存在(因此一切都会失败)。

I have been through the Turbogears documentation but they only mention Nose/nosetests and nothing else. 我已经看过Turbogears文档,但他们只提到了鼻子/鼻塞,没有别的。

Is there a way to be able to lead the application with the testing variables I rely upon with py.test ? 有没有一种方法可以用我依赖py.test的测试变量来引导应用程序?

As far as py.test's part is concerned, you can implement something like this: 就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

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. 目前,这样的conftest.py文件最好存放在您的签出根目录中,因为py-1.3.4仅在足够早地看到它时才运行此钩子。

I also looked a bit around TurboGears but didn't erasily found the mechanism how/which test.ini is actually loaded. 我还看了一下TurboGears,但没有发现该机制实际上是如何加载test.ini的。 I can update the answer if somebody can provide this information. 如果有人可以提供此信息,我可以更新答案。

HTH. HTH。 Holger 霍尔格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM