passing **settings info to unittest from nose

我怕爱的太早我们不能终老 提交于 2019-12-06 04:18:36

问题


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!


回答1:


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 WebTest app = 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 function main(global_conf, **settings).

You may also find the Pyramid docs on functional tests useful.



来源:https://stackoverflow.com/questions/7864285/passing-settings-info-to-unittest-from-nose

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!