Pyramid fails to start when webtest and sqlalchemy

2019-06-01 23:08发布

问题:

I am trying to setup a pyramid app to use both webtest and sqlalchemy. If I comment out the SQLAlchemy code, the webtests run without a problem.

[Test log ] https://travis-ci.org/caffeinated-expert/frisbee/builds/91622436

Error
Traceback (most recent call last):
  File "frisbee/frisbee/tests/test_cities_page.py", line 18, in setUp
    app = main({})
  File "frisbee/frisbee/__init__.py", line 15, in main
    engine = engine_from_config(settings, 'sqlalchemy.')
  File "build/bdist.macosx-10.10-x86_64/egg/sqlalchemy/engine/__init__.py", line 426, in engine_from_config
    url = options.pop('url')
KeyError: 'url'

In my main init file, if I comment out the sqlalchemy engine setup, then the tests run fine, but I need sqlalchemy for my project.

This is is the first time I have used webtest, so not sure if I have some other conflicting config.

[Failing code] https://github.com/caffeinated-expert/frisbee/commit/ea759015de755aca1d7bffca2845b72944572bed

回答1:

From the sqlaclhemy docs:

The only required key is (assuming the default prefix) sqlalchemy.url

In your test_cities_page.py file you call main with an empty dictionary, presumably to be unpacked for **settings. You need to add the appropriate setting to the dictionary you're passing to the function and it should run. : )