Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install pytest-gae

How to install pytest_gae

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install pytest-gae
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.2.2Never BuiltWhy not?
0.2 Available View build log
Windows (64-bit)
0.2.2Never BuiltWhy not?
0.2 Available View build log
Mac OS X (10.5+)
0.2.2Never BuiltWhy not?
0.2 Available View build log
Linux (32-bit)
0.2.2Never BuiltWhy not?
0.2 Available View build log
Linux (64-bit)
0.2.2 Available View build log
0.2 Available View build log
MIT License
Lastest release
version 0.2.2 on Jan 9th, 2014


It is pytest plugin that helps You to test applications written with Google's AppEngine.


  • --with-gae: Turns on this plugin
  • --gae-path: AppEngine's root (default google_appengine)
  • --gae-project-path: Your project's root (default ./)


Plugin does not prevent You from using code/modules that AppEngine's environment refuse to execute. So, You can easily do something like that:

import socket
import numpy

And tests just pass. But You can not run this code on AppEngine environment, because of sandboxing. See: AppEngine Docs

This plugin uses internal AppEngine's code and there is no guarantee that Google is not going to change it.


This project was inspired by nose-gae plugin for nose


Usage example

Let assume we have a directory that looks something like that

|-- gae               # AppEngine's root
|   |-- ...
|-- src               # Your project's root
|   |-- app.yaml
|   |-- index.yaml
|   |-- main.py
|-- tests             # Tests' dir
    |-- test_handlers.py
    |-- test_models.py


#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp.util import login_required
from google.appengine.api import users
from google.appengine.ext import db

class MyModel(db.Model):
    my_field = db.StringProperty(required=False)

class IndexHandler(webapp.RequestHandler):
    def get(self):

class UsersHandler(webapp.RequestHandler):

    def get(self):
        if users.is_current_user_admin():

def make_application():
    return webapp.WSGIApplication([('/index', IndexHandler),
                                   ('/users', UsersHandler)], debug=True)

def main():
    application = make_application()

if __name__ == '__main__':
Testing models


from google.appengine.ext import db
import pytest

from main import MyModel

def test_basic():
    m = MyModel(my_field='Foo')
    assert 'Foo' == m.my_field

def test_new_model():
    m = MyModel(my_field='Foo')
    pytest.raises(db.NotSavedError, lambda: m.key())

def test_saved_model():
    m = MyModel(my_field='Foo')
    assert m.key()
Using with WebTest

We could test our handlers with the help of WebTest library.

We would create three funcargs' functions that allows us to test application:

  • From anonymous user perspective
  • From authorized user perspective
  • From admin perspective

We could do that by altering os.enviroment


import os

from webtest import TestApp
from main import make_application

def pytest_funcarg__anon_app(request):
    os.environ.update({'USER_EMAIL': '',
                        'USER_ID': '',
                        'AUTH_DOMAIN': 'google',
                        'USER_IS_ADMIN': '0'})
    return TestApp(make_application())

def pytest_funcarg__user_app(request):
    os.environ.update({'USER_EMAIL': 'simple@google.com',
                       'USER_ID': '1',
                       'AUTH_DOMAIN': 'google',
                       'USER_IS_ADMIN': '0'})
    return TestApp(make_application())

def pytest_funcarg__admin_app(request):
    os.environ.update({'USER_EMAIL': 'admin@google.com',
                       'USER_ID': '2',
                       'AUTH_DOMAIN': 'google',
                       'USER_IS_ADMIN': '1'})
    return TestApp(make_application())

def test_index(anon_app):
    assert "Index" in anon_app.get('/index')

def test_user_with_user(user_app):
    assert "User" in user_app.get('/users')

def test_user_with_anon(anon_app):
    assert '302 Moved Temporarily' == anon_app.get('/users').status

def test_user_with_admin(admin_app):
    assert "Admin" in admin_app.get('/users')
py.test tests --with-gae --gae-path=gae --gae-project-path=./src/ :
platform linux2 -- Python 2.5.5 -- pytest-2.0.0
collected 7 items

tests/test_handlers.py ....
tests/test_models.py ...

============ 7 passed in 0.64 seconds ============

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.