NoseGAEをWindows環境で使う

Windows環境で使おうとしたら、dev_appserverのImportErrorが出てハマったので、備忘録を残す。

参考

基本的には

上記のpypiからソースをDLして、インストールするだけです。

python setup.py install

ところが....

そのままインストールすると、ImportErrorが出て、テストが実行出来ません。

ドキュメントを読み直してみると、デフォルトのパスが/usr/local/google_appengineになっているっぽい

When the plugin is installed, you can activate it by using the --with-gae command line option. The plugin also includes an option for setting the path to the Google App Engine python library, if it is not in the standard location of /usr/local/google_appengine.

実行する時にパスを引数で設定する
nosetests -v --with-gae --gae-lib-root="C:\Program Files\Google\google_appengine"
毎回パスを入力するのは面倒なので....

インストールする前に、パスを設定してある部分を書き換えてしまう。
.nosercを作成すれば良いようです。設定内容は記事下部の追記参照。

  • nosegae.py
class NoseGAE(Plugin):
    """
    Activate this plugin to run tests in Google App Engine dev
    environment. When the plugin is active, Google App Engine dev stubs, such
    as the stub datastore, will be available, and application code will run in
    a sandbox that restricts module loading in the same way as it is
    restricted when running under GAE.
    """
    name = 'gae'
    
    def options(self, parser, env=os.environ):
        super(NoseGAE, self).options(parser, env)
        parser.add_option(
            '--gae-lib-root', default='C:\Program Files\Google\google_appengine',
            dest='gae_lib_root',
            help='Set the path to the root directory of the Google '
            'Application Engine installation')

defaultのパスは、環境に合わせて変える。これで

nosetests -v --with-gae

だけで実行できるようになる。

追記

ブログ書いた後に、@shimizukawaさんから下記リプライを頂きました。

物は試しと、C:\Documents and Settings\\.nosercを作ってみました。

[nosetests]
gae-lib-root="C:\Program Files\Google\google_appengine"

が、上手くいかず。。。
設定の記法が間違ってるのだろうか?それとも、他に必要な設定があるのか?

もし、ソースを書き換える方法以外の解決方法をご存知の方がいれば教えて欲しい。

追記2

id:shimizukawaさんからコメントを頂き、ダブルクォートを外したら上手くいきました!
これでソースを弄る必要もなく、簡単に実行出来ます。

  • C:\Documents and Settings\\.noserc
[nosetests]
gae-lib-root=C:\Program Files\Google\google_appengine