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

pl0x
  • 30
  • 7
casibbald
  • 2,805
  • 2
  • 16
  • 14

1 Answers1

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. : )

pl0x
  • 30
  • 7
  • 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}) – casibbald Nov 17 '15 at 16:32
  • 1
    Are you passing anything to `global_config`? If you're not using it yet, I would call `app = main(global_config = None, **settings)`. – pl0x Nov 17 '15 at 16:44
  • Cheers, that worked a treat. Thank you so very much. [Diff for anyone thats interested] https://github.com/caffeinated-expert/frisbee/compare/ea759015de75...f6edaaa3cdd8 – casibbald Nov 17 '15 at 16:56
  • Glad to hear. Although I've never used Pyramid, you may want to consider checking out this video [Patterns for building large Pyramids applications](https://www.youtube.com/watch?v=NUQMr5R3dlk) 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. – pl0x Nov 17 '15 at 17:04