Pyramid fails to start when webtest and sqlalchemy are used together
Asked Answered
F

1

1

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

Flemish answered 17/11, 2015 at 16:5 Comment(0)
J
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. : )

Jacktar answered 17/11, 2015 at 16:15 Comment(4)
I have tried this and get the same error SQLALCHEMY_URL = "sqlite:///%(here)s/db/frisbee.sqlite" app = main({'url': SQLALCHEMY_URL}) or app = main({'sqlalchemy.url': SQLALCHEMY_URL})Flemish
Are you passing anything to global_config? If you're not using it yet, I would call app = main(global_config = None, **settings).Jacktar
Cheers, that worked a treat. Thank you so very much. [Diff for anyone thats interested] github.com/caffeinated-expert/frisbee/compare/…Flemish
Glad to hear. Although I've never used Pyramid, you may want to consider checking out this video Patterns for building large Pyramids applications to learn more about the idioms and design-architecture used in Pyramid. I tried finding you a boilerplate to read, but the only one I could find was a couple years old. Have a great day, mate.Jacktar

© 2022 - 2024 — McMap. All rights reserved.