From a850eadfa333af318cd11d2d1dfc0661c6c96085 Mon Sep 17 00:00:00 2001 From: Vinicius Assef Date: Sun, 6 Oct 2013 11:35:14 -0300 Subject: [PATCH] Allocate test db according to test environment --- models/db.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/models/db.py b/models/db.py index 1ea95c1..592fe07 100644 --- a/models/db.py +++ b/models/db.py @@ -1,20 +1,22 @@ # -*- coding: utf-8 -*- -import web2pytest +from web2pytest import web2pytest import os -def _i_am_running_under_tests(): - """Check if Web2py is running under a test environment. - """ - return request.is_local and web2pytest.testfile_exists() - - if not request.env.web2py_runtime_gae: ## if NOT running on Google App Engine use SQLite or other DB - if _i_am_running_under_tests(): - db = DAL('sqlite://%s_storage.sqlite' % request.application, - folder=os.path.dirname(web2pytest.testfile_name())) + if web2pytest.is_running_under_test(request): + if web2pytest.is_running_webclient(): + # When running under webclient, db cannot be ':memory:' + # because it is recreated in each request and a webclient test + # can make many requests to validate a single scenario. + db = DAL('sqlite://%s_storage.sqlite' % request.application, + folder=os.path.dirname(web2pytest.testfile_name()), + pool_size=1, + check_reserved=['all']) + else: + db = DAL('sqlite:memory:', check_reserved=['all']) else: db = DAL('sqlite://storage.sqlite', pool_size=1, check_reserved=['all']) else: