After you upgrade your app to be compatible with both Python 2 and Python 3:
Deploy and test in App Engine without shifting traffic to your app.
You may need to spend significant time fixing compatibility issues that aren't visible until you run your upgraded app in a Python 3 environment.
To avoid using production data and Google Cloud Platform quota during testing, you can use the following emulators:
Other Google Cloud Platform services such as Cloud Storage and Cloud Memorystore don't provide emulators.
Testing locally
To test your application's functionality before deploying, run the application
in your local environment with the development tools that you usually use. For
example, you can use venv to create isolated environments and pytest to run
unit tests and integration tests.
If you use Flask, you can run your app on Flask's development server with the following command:
python main.py
You can start Django applications with the following command:
python manage.py runserver
To simulate a production App Engine environment, you can run the full
Web Server Gateway Interface (WSGI) server locally. Use the same command
that is specified in the entrypoint field of your app.yaml file. If you
haven't specified a value in the entrypoint field, use the following command
to replicate the default startup behavior:
gunicorn -b :$PORT main:app
The local development server that is included in the Cloud SDK is available in alpha for Python 3 apps. We recommend you use standard Python 3 tools instead of this local development server.
Testing on App Engine before shifting traffic
Before routing traffic to your upgraded Python app, deploy the app to the
App Engine Python 3 runtime for another round of testing. For example,
to test your app's default service:
Make sure you've updated the app's configuration files for compatibility with the Python 3 runtime.
Don't change environment variables that send requests to emulators or test databases until you're ready to shift traffic to your app.
Deploy your new version, but prevent traffic from automatically routing to the new version:
gcloud app deploy --no-promote
Access your new version by navigating to the following URL:
http://VERSION_ID.default.YOUR_PROJECT_ID.appspot.com
Now you can test your new version in the App Engine runtime environment. You can debug your application by viewing its logs. For more information, see Writing Application Logs.
Requests sent to http://YOUR_PROJECT_ID.appspot.com
are routed to the version previously configured to receive traffic.
To test new versions of other services, follow the same process, but replace
default in the URL with your service's name:
http://VERSION_ID.SERVICE_ID.YOUR_PROJECT_ID.appspot.com
For more information about targeting specific services and versions, see How Requests are Routed.
Migrating traffic to your app
When you're ready to send traffic to the new version:
Update environment variables in your
app.yamlfile to send requests to your production databases and other services instead of any emulators or test data you were using.Prevent traffic being automatically routed to your new version upon deployment:
gcloud app deploy --no-promote
When you've confirmed that your app is interacting with your production databases and datastores, use the GCP Console to migrate traffic:
Select the latest version of your upgraded app and click Migrate traffic.


