python - Running tests in Google App Engine package? -


i have question concerning way in python imports modules , creates objects within packages, i'm using flask on google app engine think problem more general.

my app has following structure:

app/    application/        __init__.py        flaskr.py        models.py        mainconfig.py        etc...    tests/        tests.py        configtest.py    apptest.py    run.py 

i using google app engine launcher , works okay of time. when want run app use dev_appserver.py. appserver requires path app argument, when gets it imports stuff google app engine folder , executes app. i'm happy that.

the problem i'm having concerns tests, importantly have problem way tests load configuration @ runtime. have separate configuration tests, don't want them use mainconfig.py, should use configtests.py. unfortunately @ moment each time run tests tests using default app configuration , not own specific options - example insert data app database, , not testing database have hardcoded in config.

i run tests through apptest.py, file simple , looks this:

#!/usr/bin/python import optparse import sys import unittest2  usage = """%prog sdk_path test_path run unit tests app engine apps.  sdk_path    path sdk installation test_path   path package containing test modules"""   def main(sdk_path, test_path):     sys.path.insert(0, sdk_path)     import dev_appserver     dev_appserver.fix_sys_path()     suite = unittest2.loader.testloader().discover(test_path)     unittest2.texttestrunner(verbosity=2).run(suite)  if __name__ == '__main__':     sdk_path = u"pathtogoogle\\google\\google_appengine"        test_path = u"pathtoapp\\app\\tests\\"      main(sdk_path, test_path) 

i trying fiddle around issue while, moving tests here or there within application directory, editing code in tests setup method, fiddling around quite pointless since don't understand going on here.

i know app object created in init within application folder, , gets settings there. should mention nothing configuration in hardcoded in files in application folder, files load name of database using app.config["database"](config dictionary object, available everywhere within application). main line in tests.py sets app.test_client goes this:

from application import app  class flaskrtestcase(unittest.testcase):     def setup(self):         app.config.from_object('configtest')         self.app = app.test_client() 

what going on here, , how can 1 fix it? should in order force tests.py configuration folder instead of getting application folder?

i believe solve should add __init__.py file tests folder make module , change app.config.from_object('configtest') app.config.from_object('tests.configtest').


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -