将**设置信息从鼻子传递给单元测试
我正在使用鼻子运行单元测试。
我有 .ini 文件,例如 Production.ini、development.ini、local.ini。最后,我有一个 test.ini 文件,如下所示:
[app:main]
use = config:local.ini
# Add additional test specific configuration options as necessary.
sqlalchemy.url = sqlite:///%(here)s/tests.db
在我的测试类中,我想像在应用程序服务器代码中那样设置数据库。比如:
engine = engine_from_config(settings)
initialize_sql(engine)
dbfixture = SQLAlchemyFixture(
env=model,
engine=engine,
style=NamedDataStyle()
)
鼻子如何将“设置”传递给我的测试代码?
我一直在阅读以下链接以获取一些指导,但我无法将所有点联系起来。 http://farmdev.com/projects/fixture/using-fixture-with -pylons.html
非常感谢!
I'm running my unit tests using nose.
I have .ini files such as production.ini, development.ini, local.ini. Finally, I have a test.ini file which looks like:
[app:main]
use = config:local.ini
# Add additional test specific configuration options as necessary.
sqlalchemy.url = sqlite:///%(here)s/tests.db
In my test class I want to setup the database as I would in my app server code. Something like:
engine = engine_from_config(settings)
initialize_sql(engine)
dbfixture = SQLAlchemyFixture(
env=model,
engine=engine,
style=NamedDataStyle()
)
How does nose pass 'settings' to my test code?
I've been reading the following link for some guidance, but I haven't been able to connect all the dots. http://farmdev.com/projects/fixture/using-fixture-with-pylons.html
Thanks much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要自己解析 INI 文件中的设置。 Pylons 过去只需对“test.ini”的负载进行硬编码即可自动为您执行此操作。您有两个选项:1) 只需通过
settings = Paste.deploy.appconfig('test.ini')
加载 INI 设置或 2) 自己加载实际的 WSGI 应用程序,就像您想要的那样通过 WebTestapp = Pyramid.paster.get_app('test.ini')
使用它,它将解析 INI 文件并返回实际的 WSGI 应用程序。不幸的是,该路由无法让您直接访问 INI 文件,它会自动将设置传递给应用的启动函数main(global_conf, **settings)
。您还可以找到金字塔文档对功能测试很有用。
You will need to parse the settings from the INI file yourself. Pylons used to do this automatically for you by just hard-coding a load for "test.ini". The two options you have are 1) just load the INI settings via
settings = paste.deploy.appconfig('test.ini')
or 2) loading the actual WSGI app yourself, like if you wanted to use it via WebTestapp = pyramid.paster.get_app('test.ini')
which would parse the INI file and return an actual WSGI app. Unfortunately that route doesn't give you access to the INI file directly, it automatically just passes the settings to your app's startup functionmain(global_conf, **settings)
.You may also find the Pyramid docs on functional tests useful.