Hi,
First of all, I think that Google should do the job of establishing
good practices and environments for testing GAE applications. That's
the only pragmatic solution! I don't means big integrated things but
small pieces that we can easily integrate in our environment of
choice. A lot of people like you or a newbie like me do their best to
build just basic things and I think that a large amount of
professionals will simply go for Django or Rails if they cannot find
the elementary tools.
That said, I should also mention this interesting discussion:
http://groups.google.com/group/google-appengine-python/browse_thread/thread/435b20de9b1e5cc4?hl=en
On my side, I have specific objectives and I still cannot said that my
solution is relevant, because it's specific and not yet sufficiently
tested. I will try to explain you everything, hoping I will forget
nothing...
For me, it's a poor choice to send the files with the tests to GAE.
That's why I try to exclude Gaeunit or classic django directory
structures.
On the other hand, my business is to develop applications and not
testing environments... and on the side of GAE/django integration, I
think that App Engine Patch do a pretty good job... It would be nice
if AEP can do for me (because Google don't do it) all the job of
integrating the different parts when I run tests...
Well, to conclude on my specific motivations, I like the Netbeans6.7
IDE which offer a perfect integration of tests, with coverage
information etc... Thus, let's describe each step at a time...
1) The test runner should start GAE/django, is it possible to benefit
from AEP? Here is the patch that I did to the nb_test_runner.py
(Netbeans):
(...)# Driver for running tests from NetBeans
##############################################################################
def init_gae_django(): # ++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
os.environ['RUNNING_CONTEXT'] = 'test'
os.environ['SERVER_NAME'] = 'testserver'
os.environ['SERVER_PORT'] = '80'
os.environ['SERVER_SOFTWARE'] = 'Devel'
os.environ['USER_EMAIL'] = '' # set to '' for not logged in user
from common.appenginepatch import aecmd
aecmd.PROJECT_DIR = os.getcwd() + "/togae"
aecmd.setup_env() # +++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
if __name__ == '__main__':
import unittest
import doctest
init_gae_django() # Here my patch and funct above
######################
(...)
You should adapt this to your environment... I try to reuse the core
business of AEP to the max, because we need a lot of patches in django
to have the things working together... I am not sure that this is a
good solution, comments are welcome! (so AEP shoud simply be in your
path, Netbeans make the cwd as the root of the project and I put all
the code in the ./togae directory, what will be send to GAE... The
test are in a ./mytest directory, just beside... AEP will try to start
its sample app and make some warnings... but after I changed the
PROJECT_DIR it find the right things, like app.yaml and
settings.py...)
2) Settings.py should be adapted a bit to run in both environment,
here are my modifications for the settings.py of Rietveld/codereview:
# Copyright 2008 Google Inc.
(...)
"""Minimal Django settings."""
import os
try: # Here my patch ###################### 5 lines
if os.environ['RUNNING_CONTEXT'] == 'test':
DATABASE_ENGINE = 'appengine'
DATABASE_SUPPORTS_TRANSACTIONS = False
DJANGO_STYLE_MODEL_KIND = False
finally: APPEND_SLASH = False
DEBUG = os.environ['SERVER_SOFTWARE'].startswith('Dev')
INSTALLED_APPS = (
'codereview',
)
(...)
The try: is the only modification that I had to make to the Rietveld/
codereview code! The little problem is that the 2 environments require
different settings, that's why I use "os.environ['RUNNING_CONTEXT'] =
'test'" in the test runner! In that case, I add the things that are
required by django/AEP like DATABASE_ENGINE = 'appengine' or
DJANGO_STYLE_MODEL_KIND = False... Don't ask me where I founded
that... I never founded any documentation about them...
3) I think, that's all... Netbeans find the tests, AEP find the
project... It seems to work... with tests as the one I published in
the previous mail...
4) Nice to have: coverage information!
With the previous settings, Netbeans6.7 will give you nice coverage
information, including on the patched/zipped django code an on your
tests... (What!? You run the patched/zipped files for tests!?!?)
I prefer to receive coverage information only about the real code that
form the application, in the /togae directory. Thus I made another
little patch to the Netbeans coverage_wrapper.py:
(...)
@atexit.register
def convert_to_nb_format():
import marshal
output_file = open(output, 'wb')
c1_dict = marshal.load(open(input, 'rb'))
for k in c1_dict.keys():
if k.startswith(os.getcwd()+"/togae/"): # Here my patch
###################### 1 line
output_file.write(k.__str__())
output_file.write('\n')
x = c1_dict.get(k)
output_file.write(x.keys().__str__())
output_file.write('\n')
output_file.close()
# Run coverage.py
execfile(coverage_py_file)
(...)
That's what I have up to now... It is still not really tested and thus
every comments will be welcome!
Hope it helps,
Michel