From d9ce5d1071aaa880d07e67947afb2c70f972f221 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 17 Feb 2016 11:13:52 -0800 Subject: [PATCH] Switching the test runner to py.test This is the first step in moving to py.test. * Created `scripts/run-tests.py` that handles invoking `py.test` for all samples. * Updated `tox.ini` to use `scripts/run-tests.py` for the `{py27,py34}{-all}` environments. * Removed all unneeded `__init__.py` files. The repository is now a loose collection of independent packages instead of being one monster package. * Created `appengine/conftest.py` to do what nosegae used to do in terms of import/dev_appserver magic. Outstanding questions/issues: * Currently pytest arguments are specified in `tox.ini`. Not sure if we want to move those into `run-tests.py` or not. After this is merged, I can look into converting our tests from `unittest` style to `py.test` style, which is generally cleaner. --- .gitignore | 2 + .travis.yml | 3 +- appengine/__init__.py | 0 appengine/app_identity/__init__.py | 0 appengine/app_identity/signing/__init__.py | 0 appengine/app_identity/signing/main_test.py | 3 +- appengine/bigquery/__init__.py | 0 appengine/bigquery/main.py | 1 + appengine/bigquery/main_test.py | 3 +- appengine/blobstore/__init__.py | 0 appengine/blobstore/main_test.py | 3 +- appengine/cloudsql/__init__.py | 0 appengine/cloudsql/main_test.py | 3 +- appengine/conftest.py | 9 + appengine/i18n/__init__.py | 0 appengine/images/__init__.py | 0 appengine/images/main_test.py | 11 +- appengine/localtesting/__init__.py | 0 appengine/logging/__init__.py | 0 appengine/logging/reading_logs/__init__.py | 0 appengine/logging/reading_logs/main_test.py | 3 +- appengine/logging/writing_logs/__init__.py | 0 appengine/logging/writing_logs/main_test.py | 3 +- appengine/mailgun/__init__.py | 0 appengine/mailgun/main_test.py | 3 +- appengine/memcache/__init__.py | 0 appengine/memcache/guestbook/__init__.py | 0 appengine/memcache/guestbook/main_test.py | 4 +- appengine/multitenancy/__init__.py | 0 appengine/multitenancy/datastore_test.py | 3 +- appengine/multitenancy/memcache_test.py | 3 +- appengine/multitenancy/taskqueue_test.py | 3 +- appengine/ndb/__init__.py | 0 appengine/ndb/modeling/__init__.py | 0 .../contact_with_group_models_test.py | 3 +- .../ndb/modeling/keyproperty_models_test.py | 3 +- appengine/ndb/modeling/naive_models_test.py | 3 +- .../ndb/modeling/parent_child_models_test.py | 3 +- .../modeling/relation_model_models_test.py | 3 +- .../structured_property_models_test.py | 3 +- appengine/ndb/overview/__init__.py | 0 appengine/ndb/overview/main_test.py | 3 +- appengine/ndb/transactions/__init__.py | 0 appengine/ndb/transactions/main_test.py | 3 +- appengine/storage/__init__.py | 0 appengine/storage/main_test.py | 3 +- bigquery/__init__.py | 0 bigquery/api/__init__.py | 0 bigquery/api/async_query_test.py | 5 +- .../api/export_data_to_cloud_storage_test.py | 9 +- bigquery/api/getting_started_test.py | 5 +- bigquery/api/list_datasets_projects_test.py | 5 +- bigquery/api/load_data_by_post_test.py | 7 +- bigquery/api/load_data_from_csv_test.py | 8 +- bigquery/api/streaming_test.py | 6 +- bigquery/api/sync_query_test.py | 5 +- blog/__init__.py | 0 .../__init__.py | 0 .../blog_test.py | 9 +- .../requirements.txt | 2 +- .../wiki_test.py | 10 +- cloud_logging/__init__.py | 0 cloud_logging/api/__init__.py | 0 cloud_logging/api/list_logs_test.py | 3 +- compute/__init__.py | 0 compute/api/__init__.py | 0 compute/api/create_instance_test.py | 7 +- compute/autoscaler/__init__.py | 0 compute/autoscaler/demo/__init__.py | 0 compute/autoscaler/demo/frontend.py | 2 +- compute/autoscaler/demo/frontend_test.py | 3 +- container_engine/django_tutorial/Dockerfile | 2 +- datastore/__init__.py | 0 datastore/api/__init__.py | 0 datastore/api/requirements.txt | 2 +- datastore/api/snippets_test.py | 5 +- datastore/api/tasks_test.py | 3 +- managed_vms/__init__.py | 0 managed_vms/analytics/__init__.py | 0 managed_vms/cloudsql/__init__.py | 0 managed_vms/cloudsql/main_test.py | 3 +- managed_vms/datastore/__init__.py | 0 managed_vms/datastore/main_test.py | 3 +- managed_vms/datastore/requirements.txt | 4 +- managed_vms/disk/__init__.py | 0 managed_vms/disk/main_test.py | 3 +- managed_vms/extending_runtime/__init__.py | 0 managed_vms/extending_runtime/main_test.py | 3 +- managed_vms/hello_world/__init__.py | 0 managed_vms/hello_world/main_test.py | 3 +- managed_vms/hello_world_compat/__init__.py | 0 managed_vms/hello_world_compat/main_test.py | 3 +- managed_vms/mailgun/__init__.py | 0 managed_vms/memcache/__init__.py | 0 managed_vms/memcache/main_test.py | 3 +- managed_vms/pubsub/__init__.py | 0 managed_vms/pubsub/main.py | 1 + managed_vms/pubsub/main_test.py | 3 +- managed_vms/pubsub/requirements.txt | 4 +- managed_vms/sendgrid/__init__.py | 0 managed_vms/static_files/__init__.py | 0 managed_vms/static_files/main_test.py | 3 +- managed_vms/storage/__init__.py | 0 managed_vms/storage/main_test.py | 3 +- managed_vms/storage/requirements.txt | 2 +- managed_vms/twilio/__init__.py | 0 managed_vms/websockets/__init__.py | 0 monitoring/__init__.py | 0 monitoring/api/__init__.py | 0 monitoring/api/auth_test.py | 3 +- requirements-py27-dev.txt | 4 +- requirements-py34-dev.txt | 4 +- requirements.txt | 4 +- scripts/run-tests.py | 58 ++++++ storage/__init__.py | 0 storage/api/__init__.py | 0 storage/api/compose_objects_test.py | 3 +- storage/api/list_objects.py | 1 + storage/api/list_objects_test.py | 5 +- storage/transfer_service/__init__.py | 0 testing/__init__.py | 1 - testing/appengine.py | 28 ++- testing/cloud.py | 1 - testing/flaky.py | 5 +- tox.ini | 186 ++++++++++-------- 125 files changed, 299 insertions(+), 230 deletions(-) delete mode 100644 appengine/__init__.py delete mode 100644 appengine/app_identity/__init__.py delete mode 100644 appengine/app_identity/signing/__init__.py delete mode 100644 appengine/bigquery/__init__.py delete mode 100644 appengine/blobstore/__init__.py delete mode 100644 appengine/cloudsql/__init__.py create mode 100644 appengine/conftest.py delete mode 100644 appengine/i18n/__init__.py delete mode 100644 appengine/images/__init__.py delete mode 100644 appengine/localtesting/__init__.py delete mode 100644 appengine/logging/__init__.py delete mode 100644 appengine/logging/reading_logs/__init__.py delete mode 100644 appengine/logging/writing_logs/__init__.py delete mode 100644 appengine/mailgun/__init__.py delete mode 100644 appengine/memcache/__init__.py delete mode 100644 appengine/memcache/guestbook/__init__.py delete mode 100644 appengine/multitenancy/__init__.py delete mode 100644 appengine/ndb/__init__.py delete mode 100644 appengine/ndb/modeling/__init__.py delete mode 100644 appengine/ndb/overview/__init__.py delete mode 100644 appengine/ndb/transactions/__init__.py delete mode 100644 appengine/storage/__init__.py delete mode 100644 bigquery/__init__.py delete mode 100644 bigquery/api/__init__.py delete mode 100644 blog/__init__.py delete mode 100644 blog/introduction_to_data_models_in_cloud_datastore/__init__.py delete mode 100644 cloud_logging/__init__.py delete mode 100644 cloud_logging/api/__init__.py delete mode 100644 compute/__init__.py delete mode 100644 compute/api/__init__.py delete mode 100644 compute/autoscaler/__init__.py delete mode 100644 compute/autoscaler/demo/__init__.py delete mode 100644 datastore/__init__.py delete mode 100644 datastore/api/__init__.py delete mode 100644 managed_vms/__init__.py delete mode 100644 managed_vms/analytics/__init__.py delete mode 100644 managed_vms/cloudsql/__init__.py delete mode 100644 managed_vms/datastore/__init__.py delete mode 100644 managed_vms/disk/__init__.py delete mode 100644 managed_vms/extending_runtime/__init__.py delete mode 100644 managed_vms/hello_world/__init__.py delete mode 100644 managed_vms/hello_world_compat/__init__.py delete mode 100644 managed_vms/mailgun/__init__.py delete mode 100644 managed_vms/memcache/__init__.py delete mode 100644 managed_vms/pubsub/__init__.py delete mode 100644 managed_vms/sendgrid/__init__.py delete mode 100644 managed_vms/static_files/__init__.py delete mode 100644 managed_vms/storage/__init__.py delete mode 100644 managed_vms/twilio/__init__.py delete mode 100644 managed_vms/websockets/__init__.py delete mode 100644 monitoring/__init__.py delete mode 100644 monitoring/api/__init__.py create mode 100755 scripts/run-tests.py delete mode 100644 storage/__init__.py delete mode 100644 storage/api/__init__.py delete mode 100644 storage/transfer_service/__init__.py diff --git a/.gitignore b/.gitignore index 146119deb5f9..cbe7b6c36208 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ lib testing/resources/test-env.sh testing/resources/service-account.json secrets.tar +.cache +junit.xml diff --git a/.travis.yml b/.travis.yml index fdfd5933ba05..b43a7de8d63e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,9 +19,10 @@ before_install: - openssl aes-256-cbc -k "$secrets_password" -in secrets.tar.enc -out secrets.tar -d - tar xvf secrets.tar install: -- pip install tox +- pip install tox coverage - pip install -e git+https://github.com/GoogleCloudPlatform/python-repo-tools#egg=python-repo-tools - gcp-python-repo-tools download-appengine-sdk `dirname "${GAE_PYTHONPATH}"` script: - source ${TRAVIS_BUILD_DIR}/testing/resources/test-env.sh - tox +- coverage report diff --git a/appengine/__init__.py b/appengine/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/app_identity/__init__.py b/appengine/app_identity/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/app_identity/signing/__init__.py b/appengine/app_identity/signing/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/app_identity/signing/main_test.py b/appengine/app_identity/signing/main_test.py index 7d2133838bdc..18a1ed4fc4b2 100644 --- a/appengine/app_identity/signing/main_test.py +++ b/appengine/app_identity/signing/main_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import AppEngineTest import webtest -from . import main - class TestAppIdentityHandler(AppEngineTest): def setUp(self): diff --git a/appengine/bigquery/__init__.py b/appengine/bigquery/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/bigquery/main.py b/appengine/bigquery/main.py index fe825622d6bc..1c035272ce7a 100644 --- a/appengine/bigquery/main.py +++ b/appengine/bigquery/main.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + # [START all] """ diff --git a/appengine/bigquery/main_test.py b/appengine/bigquery/main_test.py index de170a50b244..31405bd19ec7 100644 --- a/appengine/bigquery/main_test.py +++ b/appengine/bigquery/main_test.py @@ -15,12 +15,11 @@ import re from apiclient.http import HttpMock +import main import mock import testing import webtest -from . import main - class TestAuthSample(testing.AppEngineTest): diff --git a/appengine/blobstore/__init__.py b/appengine/blobstore/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/blobstore/main_test.py b/appengine/blobstore/main_test.py index da6e6bfeb675..ead93e061235 100644 --- a/appengine/blobstore/main_test.py +++ b/appengine/blobstore/main_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main import testing import webtest -from . import main - class TestBlobstoreSample(testing.AppEngineTest): diff --git a/appengine/cloudsql/__init__.py b/appengine/cloudsql/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/cloudsql/main_test.py b/appengine/cloudsql/main_test.py index 2ad2cacc071b..771351e68814 100644 --- a/appengine/cloudsql/main_test.py +++ b/appengine/cloudsql/main_test.py @@ -16,11 +16,10 @@ import re from unittest.case import SkipTest +import main import testing import webtest -from . import main - class TestMySQLSample(testing.AppEngineTest): diff --git a/appengine/conftest.py b/appengine/conftest.py new file mode 100644 index 000000000000..fa252fd1f58f --- /dev/null +++ b/appengine/conftest.py @@ -0,0 +1,9 @@ +import testing.appengine + + +def pytest_configure(config): + testing.appengine.setup_sdk_imports() + + +def pytest_runtest_call(item): + testing.appengine.import_appengine_config() diff --git a/appengine/i18n/__init__.py b/appengine/i18n/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/images/__init__.py b/appengine/images/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/images/main_test.py b/appengine/images/main_test.py index 25c264470ff2..0b14c8f7854d 100644 --- a/appengine/images/main_test.py +++ b/appengine/images/main_test.py @@ -12,20 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main import mock from testing import AppEngineTest import webtest -from . import main - class TestHandlers(AppEngineTest): def setUp(self): super(TestHandlers, self).setUp() - - # Workaround for other tests clobbering our Greeting model. - reload(main) - self.app = webtest.TestApp(main.app) def test_get(self): @@ -40,7 +35,7 @@ def test_get(self): # Let's check if the response is correct. self.assertEqual(response.status_int, 200) - @mock.patch('appengine.images.main.images') + @mock.patch('main.images') def test_post(self, mock_images): mock_images.resize.return_value = 'asdf' @@ -68,7 +63,7 @@ def test_img_missing(self): # Bogus image id, should get error self.app.get('/img?img_id=123', status=500) - @mock.patch('appengine.images.main.images') + @mock.patch('main.images') def test_post_and_get(self, mock_images): mock_images.resize.return_value = 'asdf' diff --git a/appengine/localtesting/__init__.py b/appengine/localtesting/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/logging/__init__.py b/appengine/logging/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/logging/reading_logs/__init__.py b/appengine/logging/reading_logs/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/logging/reading_logs/main_test.py b/appengine/logging/reading_logs/main_test.py index 0dcc8cd61bc3..51dc1234eab5 100644 --- a/appengine/logging/reading_logs/main_test.py +++ b/appengine/logging/reading_logs/main_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import AppEngineTest import webtest -from . import main - class TestReadingLogs(AppEngineTest): def setUp(self): diff --git a/appengine/logging/writing_logs/__init__.py b/appengine/logging/writing_logs/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/logging/writing_logs/main_test.py b/appengine/logging/writing_logs/main_test.py index 339caa4ef662..b6b27fb70196 100644 --- a/appengine/logging/writing_logs/main_test.py +++ b/appengine/logging/writing_logs/main_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import AppEngineTest import webtest -from . import main - class TestWritingLogs(AppEngineTest): def setUp(self): diff --git a/appengine/mailgun/__init__.py b/appengine/mailgun/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/mailgun/main_test.py b/appengine/mailgun/main_test.py index dbd3345bb442..1c47c7aabadf 100644 --- a/appengine/mailgun/main_test.py +++ b/appengine/mailgun/main_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import AppEngineTest, Http2Mock import webtest -from . import main - class TestMailgunHandlers(AppEngineTest): def setUp(self): diff --git a/appengine/memcache/__init__.py b/appengine/memcache/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/memcache/guestbook/__init__.py b/appengine/memcache/guestbook/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/memcache/guestbook/main_test.py b/appengine/memcache/guestbook/main_test.py index 62bf0e92aa71..7c70b65bf284 100644 --- a/appengine/memcache/guestbook/main_test.py +++ b/appengine/memcache/guestbook/main_test.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. + +import main from testing import AppEngineTest import webtest -from . import main - class TestHandlers(AppEngineTest): diff --git a/appengine/multitenancy/__init__.py b/appengine/multitenancy/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/multitenancy/datastore_test.py b/appengine/multitenancy/datastore_test.py index abdf9eee6636..e82f59ebf919 100644 --- a/appengine/multitenancy/datastore_test.py +++ b/appengine/multitenancy/datastore_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import datastore import testing import webtest -from . import datastore - class TestNamespaceDatastoreSample(testing.AppEngineTest): diff --git a/appengine/multitenancy/memcache_test.py b/appengine/multitenancy/memcache_test.py index df30155a6a4c..305e3c851af8 100644 --- a/appengine/multitenancy/memcache_test.py +++ b/appengine/multitenancy/memcache_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import memcache import testing import webtest -from . import memcache - class TestNamespaceMemcacheSample(testing.AppEngineTest): diff --git a/appengine/multitenancy/taskqueue_test.py b/appengine/multitenancy/taskqueue_test.py index a8dd703a473a..9f4d12da9ef2 100644 --- a/appengine/multitenancy/taskqueue_test.py +++ b/appengine/multitenancy/taskqueue_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import taskqueue import testing import webtest -from . import taskqueue - class TestNamespaceTaskQueueSample(testing.AppEngineTest): diff --git a/appengine/ndb/__init__.py b/appengine/ndb/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/ndb/modeling/__init__.py b/appengine/ndb/modeling/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/ndb/modeling/contact_with_group_models_test.py b/appengine/ndb/modeling/contact_with_group_models_test.py index 286948bc5f4d..0b0f694c9610 100644 --- a/appengine/ndb/modeling/contact_with_group_models_test.py +++ b/appengine/ndb/modeling/contact_with_group_models_test.py @@ -14,11 +14,10 @@ """Test classes for code snippet for modeling article.""" +import contact_with_group_models as models from google.appengine.ext import ndb from testing import AppEngineTest -from . import contact_with_group_models as models - class ContactTestCase(AppEngineTest): """A test case for the Contact model with groups.""" diff --git a/appengine/ndb/modeling/keyproperty_models_test.py b/appengine/ndb/modeling/keyproperty_models_test.py index ec0cf87d8baa..fa54b3d211b8 100644 --- a/appengine/ndb/modeling/keyproperty_models_test.py +++ b/appengine/ndb/modeling/keyproperty_models_test.py @@ -16,10 +16,9 @@ import unittest +import keyproperty_models as models from testing import AppEngineTest -from . import keyproperty_models as models - class ContactTestCase(AppEngineTest): """A test case for the Contact model class with KeyProperty.""" diff --git a/appengine/ndb/modeling/naive_models_test.py b/appengine/ndb/modeling/naive_models_test.py index 07d5935e0b13..360c88f55f8f 100644 --- a/appengine/ndb/modeling/naive_models_test.py +++ b/appengine/ndb/modeling/naive_models_test.py @@ -14,10 +14,9 @@ """Test classes for code snippet for modeling article.""" +import naive_models as models from testing import AppEngineTest -from . import naive_models as models - class ContactTestCase(AppEngineTest): """A test case for the naive Contact model classe.""" diff --git a/appengine/ndb/modeling/parent_child_models_test.py b/appengine/ndb/modeling/parent_child_models_test.py index 95f3d876ad7e..f10673a63caa 100644 --- a/appengine/ndb/modeling/parent_child_models_test.py +++ b/appengine/ndb/modeling/parent_child_models_test.py @@ -15,10 +15,9 @@ """Test classes for code snippet for modeling article.""" from google.appengine.ext import ndb +import parent_child_models as models from testing import AppEngineTest -from . import parent_child_models as models - class ContactTestCase(AppEngineTest): """A test case for the Contact model class with KeyProperty.""" diff --git a/appengine/ndb/modeling/relation_model_models_test.py b/appengine/ndb/modeling/relation_model_models_test.py index 45eb7805617a..d954d96d5ed1 100644 --- a/appengine/ndb/modeling/relation_model_models_test.py +++ b/appengine/ndb/modeling/relation_model_models_test.py @@ -15,10 +15,9 @@ """Test classes for code snippet for modeling article.""" from google.appengine.ext import ndb +import relation_model_models as models from testing import AppEngineTest -from . import relation_model_models as models - class ContactTestCase(AppEngineTest): """A test case for the Contact model with relationship model.""" diff --git a/appengine/ndb/modeling/structured_property_models_test.py b/appengine/ndb/modeling/structured_property_models_test.py index 0e60d71d14dd..11e5e47d6272 100644 --- a/appengine/ndb/modeling/structured_property_models_test.py +++ b/appengine/ndb/modeling/structured_property_models_test.py @@ -14,10 +14,9 @@ """Test classes for code snippet for modeling article.""" +import structured_property_models as models from testing import AppEngineTest -from . import structured_property_models as models - class ContactTestCase(AppEngineTest): """A test case for the Contact model with StructuredProperty.""" diff --git a/appengine/ndb/overview/__init__.py b/appengine/ndb/overview/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/ndb/overview/main_test.py b/appengine/ndb/overview/main_test.py index 2cc6dd2badb0..8fbc5f9de5f4 100644 --- a/appengine/ndb/overview/main_test.py +++ b/appengine/ndb/overview/main_test.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import AppEngineTest import webtest -from . import main - class TestHandlers(AppEngineTest): def test_hello(self): diff --git a/appengine/ndb/transactions/__init__.py b/appengine/ndb/transactions/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/ndb/transactions/main_test.py b/appengine/ndb/transactions/main_test.py index 988bdbb5e9c4..b7aa42e8e9e0 100644 --- a/appengine/ndb/transactions/main_test.py +++ b/appengine/ndb/transactions/main_test.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import AppEngineTest -from . import main - class TestHandlers(AppEngineTest): def setUp(self): diff --git a/appengine/storage/__init__.py b/appengine/storage/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/appengine/storage/main_test.py b/appengine/storage/main_test.py index 5dbddc985305..96787217fbfe 100644 --- a/appengine/storage/main_test.py +++ b/appengine/storage/main_test.py @@ -13,11 +13,10 @@ # limitations under the License. import re +import main import testing import webtest -from . import main - class TestStorageSample(testing.AppEngineTest): diff --git a/bigquery/__init__.py b/bigquery/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/bigquery/api/__init__.py b/bigquery/api/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/bigquery/api/async_query_test.py b/bigquery/api/async_query_test.py index 575d90326df3..005b1b0d7f4f 100644 --- a/bigquery/api/async_query_test.py +++ b/bigquery/api/async_query_test.py @@ -10,13 +10,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# + import json +from async_query import main import testing -from .async_query import main - class TestAsyncQuery(testing.CloudTest): diff --git a/bigquery/api/export_data_to_cloud_storage_test.py b/bigquery/api/export_data_to_cloud_storage_test.py index 135b2bf075d5..77820bb2792c 100644 --- a/bigquery/api/export_data_to_cloud_storage_test.py +++ b/bigquery/api/export_data_to_cloud_storage_test.py @@ -10,16 +10,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -"""Tests for export_table_to_gcs.""" -from nose.plugins.attrib import attr +from export_data_to_cloud_storage import main +import pytest from testing import CloudTest -from .export_data_to_cloud_storage import main - -@attr('slow') +@pytest.mark.slow class TestExportTableToGCS(CloudTest): dataset_id = 'test_dataset' table_id = 'test_table' diff --git a/bigquery/api/getting_started_test.py b/bigquery/api/getting_started_test.py index 4d32f4d44cbc..74114db8f5e8 100644 --- a/bigquery/api/getting_started_test.py +++ b/bigquery/api/getting_started_test.py @@ -10,13 +10,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# + import re +from getting_started import main import testing -from .getting_started import main - class TestGettingStarted(testing.CloudTest): def test_main(self): diff --git a/bigquery/api/list_datasets_projects_test.py b/bigquery/api/list_datasets_projects_test.py index 2dd92a8d6b9b..09d4ad52d51a 100644 --- a/bigquery/api/list_datasets_projects_test.py +++ b/bigquery/api/list_datasets_projects_test.py @@ -10,13 +10,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# + import re +from list_datasets_projects import main import testing -from .list_datasets_projects import main - class TestListDatasetsProjects(testing.CloudTest): diff --git a/bigquery/api/load_data_by_post_test.py b/bigquery/api/load_data_by_post_test.py index 08286e144b1e..d88c7fcf0e7a 100644 --- a/bigquery/api/load_data_by_post_test.py +++ b/bigquery/api/load_data_by_post_test.py @@ -13,13 +13,12 @@ import re -from nose.plugins.attrib import attr +from load_data_by_post import load_data +import pytest import testing -from .load_data_by_post import load_data - -@attr('slow') +@pytest.mark.slow class TestLoadDataByPost(testing.CloudTest): dataset_id = 'ephemeral_test_dataset' table_id = 'load_data_by_post' diff --git a/bigquery/api/load_data_from_csv_test.py b/bigquery/api/load_data_from_csv_test.py index fd64fdeca9a2..3bb989a6fceb 100644 --- a/bigquery/api/load_data_from_csv_test.py +++ b/bigquery/api/load_data_from_csv_test.py @@ -11,13 +11,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from nose.plugins.attrib import attr -from testing import CloudTest -from .load_data_from_csv import main +from load_data_from_csv import main +import pytest +from testing import CloudTest -@attr('slow') +@pytest.mark.slow class TestLoadDataFromCSV(CloudTest): dataset_id = 'test_dataset' table_id = 'test_import_table' diff --git a/bigquery/api/streaming_test.py b/bigquery/api/streaming_test.py index 29160231e2fe..44751e47727d 100644 --- a/bigquery/api/streaming_test.py +++ b/bigquery/api/streaming_test.py @@ -10,14 +10,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -"""Tests for export_table_to_gcs.""" + import json +import streaming from testing import capture_stdout, CloudTest -from . import streaming - class TestStreaming(CloudTest): dataset_id = 'test_dataset' diff --git a/bigquery/api/sync_query_test.py b/bigquery/api/sync_query_test.py index 975095990424..c39f6af0abc4 100644 --- a/bigquery/api/sync_query_test.py +++ b/bigquery/api/sync_query_test.py @@ -10,13 +10,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# + import json +from sync_query import main from testing import capture_stdout, CloudTest -from .sync_query import main - class TestSyncQuery(CloudTest): diff --git a/blog/__init__.py b/blog/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/blog/introduction_to_data_models_in_cloud_datastore/__init__.py b/blog/introduction_to_data_models_in_cloud_datastore/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/blog/introduction_to_data_models_in_cloud_datastore/blog_test.py b/blog/introduction_to_data_models_in_cloud_datastore/blog_test.py index 3475b212b440..6da23560cf07 100644 --- a/blog/introduction_to_data_models_in_cloud_datastore/blog_test.py +++ b/blog/introduction_to_data_models_in_cloud_datastore/blog_test.py @@ -10,14 +10,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -from nose.plugins.attrib import attr -from testing import CloudTest -from .blog import main +from blog import main +import pytest +from testing import CloudTest -@attr('slow') +@pytest.mark.slow class BlogTestCase(CloudTest): """Simple test case that ensures the blog code doesn't throw any errors.""" diff --git a/blog/introduction_to_data_models_in_cloud_datastore/requirements.txt b/blog/introduction_to_data_models_in_cloud_datastore/requirements.txt index 71ed6eb5cdbf..68b08969e39a 100644 --- a/blog/introduction_to_data_models_in_cloud_datastore/requirements.txt +++ b/blog/introduction_to_data_models_in_cloud_datastore/requirements.txt @@ -1 +1 @@ -gcloud==0.9.0 +gcloud==0.10.0 diff --git a/blog/introduction_to_data_models_in_cloud_datastore/wiki_test.py b/blog/introduction_to_data_models_in_cloud_datastore/wiki_test.py index 17cfe5396120..4ad37a2ba269 100644 --- a/blog/introduction_to_data_models_in_cloud_datastore/wiki_test.py +++ b/blog/introduction_to_data_models_in_cloud_datastore/wiki_test.py @@ -10,14 +10,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -from nose.plugins.attrib import attr -from testing import CloudTest -from .wiki import main + +import pytest +from testing import CloudTest +from wiki import main -@attr('slow') +@pytest.mark.slow class WikiTestCase(CloudTest): """Simple test case that ensures the wiki code doesn't throw any errors.""" diff --git a/cloud_logging/__init__.py b/cloud_logging/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/cloud_logging/api/__init__.py b/cloud_logging/api/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/cloud_logging/api/list_logs_test.py b/cloud_logging/api/list_logs_test.py index 0f5d7d598b07..fc7feb727835 100644 --- a/cloud_logging/api/list_logs_test.py +++ b/cloud_logging/api/list_logs_test.py @@ -14,10 +14,9 @@ import re import unittest +import list_logs import testing -from . import list_logs - class TestListLogs(testing.CloudTest): diff --git a/compute/__init__.py b/compute/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/compute/api/__init__.py b/compute/api/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/compute/api/create_instance_test.py b/compute/api/create_instance_test.py index 9bf852d78870..beb7c93f85b4 100644 --- a/compute/api/create_instance_test.py +++ b/compute/api/create_instance_test.py @@ -13,13 +13,12 @@ import re -from nose.plugins.attrib import attr +from create_instance import main +import pytest import testing -from .create_instance import main - -@attr('slow') +@pytest.mark.slow class TestComputeGettingStarted(testing.CloudTest): def test_main(self): diff --git a/compute/autoscaler/__init__.py b/compute/autoscaler/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/compute/autoscaler/demo/__init__.py b/compute/autoscaler/demo/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/compute/autoscaler/demo/frontend.py b/compute/autoscaler/demo/frontend.py index e464e9af7856..c0d1ae600301 100644 --- a/compute/autoscaler/demo/frontend.py +++ b/compute/autoscaler/demo/frontend.py @@ -10,7 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# + """A simple web server which responds to HTTP GET requests by consuming CPU. This binary runs in a GCE VM. It serves HTTP requests on port 80. Every request with path '/service' consumes 1 core-second of CPU time, with the timeout of diff --git a/compute/autoscaler/demo/frontend_test.py b/compute/autoscaler/demo/frontend_test.py index 6ef175faea08..dc9deb3bad4a 100644 --- a/compute/autoscaler/demo/frontend_test.py +++ b/compute/autoscaler/demo/frontend_test.py @@ -11,11 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# import unittest -from . import frontend +import frontend class FakeTime(object): diff --git a/container_engine/django_tutorial/Dockerfile b/container_engine/django_tutorial/Dockerfile index 5d223d0bac17..220f232cb718 100644 --- a/container_engine/django_tutorial/Dockerfile +++ b/container_engine/django_tutorial/Dockerfile @@ -10,7 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# + # [START docker] # The Google App Engine python runtime is Debian Jessie with Python installed diff --git a/datastore/__init__.py b/datastore/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/datastore/api/__init__.py b/datastore/api/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/datastore/api/requirements.txt b/datastore/api/requirements.txt index 71ed6eb5cdbf..68b08969e39a 100644 --- a/datastore/api/requirements.txt +++ b/datastore/api/requirements.txt @@ -1 +1 @@ -gcloud==0.9.0 +gcloud==0.10.0 diff --git a/datastore/api/snippets_test.py b/datastore/api/snippets_test.py index 24b45e3575d9..973c18fb1a2d 100644 --- a/datastore/api/snippets_test.py +++ b/datastore/api/snippets_test.py @@ -10,15 +10,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# + from functools import wraps import time from gcloud import datastore +import snippets from testing import CloudTest, mark_flaky -from . import snippets - def eventually_consistent(f): @wraps(f) diff --git a/datastore/api/tasks_test.py b/datastore/api/tasks_test.py index 58452f899b17..528a40702e50 100644 --- a/datastore/api/tasks_test.py +++ b/datastore/api/tasks_test.py @@ -12,10 +12,9 @@ # limitations under the License. from gcloud import datastore +import tasks from testing import CloudTest, mark_flaky -from . import tasks - @mark_flaky class DatastoreTasksTest(CloudTest): diff --git a/managed_vms/__init__.py b/managed_vms/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/analytics/__init__.py b/managed_vms/analytics/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/cloudsql/__init__.py b/managed_vms/cloudsql/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/cloudsql/main_test.py b/managed_vms/cloudsql/main_test.py index 66d7eb3f9601..ba275e4c4906 100644 --- a/managed_vms/cloudsql/main_test.py +++ b/managed_vms/cloudsql/main_test.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import CloudTest -from . import main - class CloudSqlTest(CloudTest): diff --git a/managed_vms/datastore/__init__.py b/managed_vms/datastore/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/datastore/main_test.py b/managed_vms/datastore/main_test.py index e883e7251d68..3e8831cb483a 100644 --- a/managed_vms/datastore/main_test.py +++ b/managed_vms/datastore/main_test.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import CloudTest -from . import main - class DatastoreTest(CloudTest): diff --git a/managed_vms/datastore/requirements.txt b/managed_vms/datastore/requirements.txt index 657613488e1c..1d06147596b6 100644 --- a/managed_vms/datastore/requirements.txt +++ b/managed_vms/datastore/requirements.txt @@ -1,4 +1,4 @@ Flask==0.10.1 -gcloud==0.9.0 +gcloud==0.10.0 gunicorn==19.4.5 -oauth2client==1.5.2 +oauth2client==2.0.0 diff --git a/managed_vms/disk/__init__.py b/managed_vms/disk/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/disk/main_test.py b/managed_vms/disk/main_test.py index 15aa04917887..d341fe5e8352 100644 --- a/managed_vms/disk/main_test.py +++ b/managed_vms/disk/main_test.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import CloudTest -from . import main - class DiskTest(CloudTest): diff --git a/managed_vms/extending_runtime/__init__.py b/managed_vms/extending_runtime/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/extending_runtime/main_test.py b/managed_vms/extending_runtime/main_test.py index 583ebbad0a8d..716e139b39e0 100644 --- a/managed_vms/extending_runtime/main_test.py +++ b/managed_vms/extending_runtime/main_test.py @@ -14,11 +14,10 @@ import os +import main from nose.plugins.skip import SkipTest from testing import CloudTest -from . import main - class ExtendingRuntimeTest(CloudTest): diff --git a/managed_vms/hello_world/__init__.py b/managed_vms/hello_world/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/hello_world/main_test.py b/managed_vms/hello_world/main_test.py index 34a3ab507b9d..f28b07ad42f7 100644 --- a/managed_vms/hello_world/main_test.py +++ b/managed_vms/hello_world/main_test.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import CloudTest -from . import main - class HelloWorldTest(CloudTest): diff --git a/managed_vms/hello_world_compat/__init__.py b/managed_vms/hello_world_compat/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/hello_world_compat/main_test.py b/managed_vms/hello_world_compat/main_test.py index 34a3ab507b9d..f28b07ad42f7 100644 --- a/managed_vms/hello_world_compat/main_test.py +++ b/managed_vms/hello_world_compat/main_test.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import CloudTest -from . import main - class HelloWorldTest(CloudTest): diff --git a/managed_vms/mailgun/__init__.py b/managed_vms/mailgun/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/memcache/__init__.py b/managed_vms/memcache/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/memcache/main_test.py b/managed_vms/memcache/main_test.py index d4572f952e1b..e005866f15f7 100644 --- a/managed_vms/memcache/main_test.py +++ b/managed_vms/memcache/main_test.py @@ -14,10 +14,9 @@ from unittest.case import SkipTest +import main from testing import CloudTest -from . import main - class MemcacheTest(CloudTest): diff --git a/managed_vms/pubsub/__init__.py b/managed_vms/pubsub/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/pubsub/main.py b/managed_vms/pubsub/main.py index 0daf8bb5ad13..f9b3893fb4a3 100644 --- a/managed_vms/pubsub/main.py +++ b/managed_vms/pubsub/main.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + # [START app] import base64 import json diff --git a/managed_vms/pubsub/main_test.py b/managed_vms/pubsub/main_test.py index b34662134549..84430e8c0906 100644 --- a/managed_vms/pubsub/main_test.py +++ b/managed_vms/pubsub/main_test.py @@ -16,10 +16,9 @@ import json import os +import main from testing import CloudTest -from . import main - class PubSubTest(CloudTest): def setUp(self): diff --git a/managed_vms/pubsub/requirements.txt b/managed_vms/pubsub/requirements.txt index 657613488e1c..1d06147596b6 100644 --- a/managed_vms/pubsub/requirements.txt +++ b/managed_vms/pubsub/requirements.txt @@ -1,4 +1,4 @@ Flask==0.10.1 -gcloud==0.9.0 +gcloud==0.10.0 gunicorn==19.4.5 -oauth2client==1.5.2 +oauth2client==2.0.0 diff --git a/managed_vms/sendgrid/__init__.py b/managed_vms/sendgrid/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/static_files/__init__.py b/managed_vms/static_files/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/static_files/main_test.py b/managed_vms/static_files/main_test.py index 9861d6e953ea..d230546e2fdf 100644 --- a/managed_vms/static_files/main_test.py +++ b/managed_vms/static_files/main_test.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main from testing import CloudTest -from . import main - class StaticFilesTest(CloudTest): diff --git a/managed_vms/storage/__init__.py b/managed_vms/storage/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/storage/main_test.py b/managed_vms/storage/main_test.py index 3037ffdf63d1..50e6d702b439 100644 --- a/managed_vms/storage/main_test.py +++ b/managed_vms/storage/main_test.py @@ -12,12 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import main import requests from six import BytesIO from testing import CloudTest -from . import main - class StorageTest(CloudTest): def setUp(self): diff --git a/managed_vms/storage/requirements.txt b/managed_vms/storage/requirements.txt index 65f0fb67e2af..2961dded16a6 100644 --- a/managed_vms/storage/requirements.txt +++ b/managed_vms/storage/requirements.txt @@ -1,3 +1,3 @@ Flask==0.10.1 -gcloud==0.9.0 +gcloud==0.10.0 gunicorn==19.4.5 diff --git a/managed_vms/twilio/__init__.py b/managed_vms/twilio/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/managed_vms/websockets/__init__.py b/managed_vms/websockets/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/monitoring/__init__.py b/monitoring/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/monitoring/api/__init__.py b/monitoring/api/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/monitoring/api/auth_test.py b/monitoring/api/auth_test.py index 5bd05c0f4a0f..49725a5f2b1a 100644 --- a/monitoring/api/auth_test.py +++ b/monitoring/api/auth_test.py @@ -13,10 +13,9 @@ import re +import auth import testing -from . import auth - class TestTimeseriesList(testing.CloudTest): diff --git a/requirements-py27-dev.txt b/requirements-py27-dev.txt index 66a2b53c0620..78ea9f6036de 100644 --- a/requirements-py27-dev.txt +++ b/requirements-py27-dev.txt @@ -14,7 +14,7 @@ PyYAML==3.11 waitress==0.8.10 WebOb==1.6.0a0 WebTest==2.0.20 -Werkzeug==0.11.3 +Werkzeug==0.11.4 nose-timer==0.6.0 Flask-SQLAlchemy==2.1 PyMySQL==0.7.1 @@ -26,3 +26,5 @@ twilio==6.3.dev0 sendgrid==1.6.22 Flask-Sockets==0.2.0 mysql-python==1.2.5 +pytest==2.8.7 +pytest-cov==2.2.1 diff --git a/requirements-py34-dev.txt b/requirements-py34-dev.txt index e9b43e36f825..c0b044fdf10b 100644 --- a/requirements-py34-dev.txt +++ b/requirements-py34-dev.txt @@ -14,7 +14,7 @@ PyYAML==3.11 waitress==0.8.10 WebOb==1.6.0a0 WebTest==2.0.20 -Werkzeug==0.11.3 +Werkzeug==0.11.4 nose-timer==0.6.0 Flask-SQLAlchemy==2.1 PyMySQL==0.7.1 @@ -24,3 +24,5 @@ flaky==3.1.0 Django==1.9.2 twilio==6.3.dev0 sendgrid==1.6.22 +pytest==2.8.7 +pytest-cov==2.2.1 diff --git a/requirements.txt b/requirements.txt index edc85fec26ab..45676501da5d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -gcloud==0.9.0 +gcloud==0.10.0 google-api-python-client==1.4.2 -oauth2client==1.5.2 +oauth2client==2.0.0 requests[security]==2.9.1 diff --git a/scripts/run-tests.py b/scripts/run-tests.py new file mode 100755 index 000000000000..524de1c445fb --- /dev/null +++ b/scripts/run-tests.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +# Copyright (C) 2013 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import subprocess +import sys + +import pytest # flake8: noqa +import _pytest.main + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--junit', action='store_true', help='Output junit test report.') + parser.add_argument('--run-slow', action='store_true', help='Run slow tests.') + parser.add_argument( + 'directories', nargs='+', help='Directories to run py.test on.') + args = parser.parse_args() + + extra_args = [] + + if not args.run_slow: + extra_args.append('-m not slow and not flaky') + extra_args.append('--no-flaky-report') + + for directory in args.directories: + per_directory_args = [] + + if args.junit: + per_directory_args.append( + '--junitxml={}/junit.xml'.format(directory)) + + # We could use pytest.main, however, we need import isolatation between + # test runs. Without using subprocess, any test files that are named + # the same will cause pytest to fail. Rather than do sys.module magic + # between runs, it's cleaner to just do a subprocess. + code = subprocess.call( + ['py.test'] + extra_args + per_directory_args + [directory]) + + if code not in ( + _pytest.main.EXIT_OK, _pytest.main.EXIT_NOTESTSCOLLECTED): + sys.exit(code) + +if __name__ == '__main__': + main() diff --git a/storage/__init__.py b/storage/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/storage/api/__init__.py b/storage/api/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/storage/api/compose_objects_test.py b/storage/api/compose_objects_test.py index 5497d2cec12b..071edadc2f98 100644 --- a/storage/api/compose_objects_test.py +++ b/storage/api/compose_objects_test.py @@ -11,10 +11,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from compose_objects import main from testing import CloudTest -from .compose_objects import main - class TestComposeObjects(CloudTest): def test_main(self): diff --git a/storage/api/list_objects.py b/storage/api/list_objects.py index 705aab8c6371..965ef91f9740 100644 --- a/storage/api/list_objects.py +++ b/storage/api/list_objects.py @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + # [START all] """Command-line sample application for listing all objects in a bucket using diff --git a/storage/api/list_objects_test.py b/storage/api/list_objects_test.py index ecb9785faf5b..4cdee901937c 100644 --- a/storage/api/list_objects_test.py +++ b/storage/api/list_objects_test.py @@ -10,10 +10,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -from testing import CloudTest -from .list_objects import main +from list_objects import main +from testing import CloudTest class TestListObjects(CloudTest): diff --git a/storage/transfer_service/__init__.py b/storage/transfer_service/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/testing/__init__.py b/testing/__init__.py index 970b3ce1d730..b3373d37cd15 100644 --- a/testing/__init__.py +++ b/testing/__init__.py @@ -10,7 +10,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# from .appengine import AppEngineTest from .cloud import CloudTest diff --git a/testing/appengine.py b/testing/appengine.py index 3db88e643e21..565ba8e0eb7b 100644 --- a/testing/appengine.py +++ b/testing/appengine.py @@ -10,13 +10,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# """ Common testing tools for Google App Engine tests. """ import os +import sys import tempfile from nose.plugins.skip import SkipTest @@ -33,6 +33,32 @@ from .cloud import CloudTest +def setup_sdk_imports(): + """Sets up appengine SDK third-party imports.""" + if 'google' in sys.modules: + # Some packages, such as protobuf, clobber the google + # namespace package. This prevents that. + reload(sys.modules['google']) + + # This sets up google-provided libraries. + import dev_appserver + dev_appserver.fix_sys_path() + + # Fixes timezone and other os-level items. + import google.appengine.tools.os_compat + (google.appengine.tools.os_compat) + + +def import_appengine_config(): + """Imports an application appengine_config.py. This is used to + mimic the behavior of the runtime.""" + try: + import appengine_config + (appengine_config) + except ImportError: + pass + + class AppEngineTest(CloudTest): """A base test case for common setup/teardown tasks for test.""" def setUp(self): diff --git a/testing/cloud.py b/testing/cloud.py index f77a542fd102..bb64114820a2 100644 --- a/testing/cloud.py +++ b/testing/cloud.py @@ -10,7 +10,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# """ Common testing tools for cloud samples. diff --git a/testing/flaky.py b/testing/flaky.py index fc85431ab1f1..2174a9a832c0 100644 --- a/testing/flaky.py +++ b/testing/flaky.py @@ -10,7 +10,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# """ Tools for dealing with flaky tests. @@ -20,7 +19,7 @@ from flaky import flaky import gcloud -from nose.plugins.attrib import attr +import pytest def flaky_filter(e, *args): @@ -34,4 +33,4 @@ def flaky_filter(e, *args): def mark_flaky(f): """Makes a test retry on remote service errors.""" return flaky(max_runs=3, rerun_filter=flaky_filter)( - attr('flaky')(f)) + pytest.mark.flaky(f)) diff --git a/tox.ini b/tox.ini index 5eeadcc337e1..b9bc6a1d9604 100644 --- a/tox.ini +++ b/tox.ini @@ -7,111 +7,133 @@ passenv = * basepython = python2.7 deps = -rrequirements.txt -commonargs = - --with-timer - --with-coverage - --cover-tests - --cover-branches - --cover-inclusive - --with-flaky - --no-success-flaky-report - --exclude-dir=managed_vms/django_cloudsql - --exclude-dir=managed_vms/hello_world_django - -[testenv:reqcheck] -commands = - bash -c "find . -name requirements\*.txt |\ - xargs -P 4 -n 1 gcp-python-repo-tools check-requirements" -whitelist_externals = - bash - find - xargs - gcp-python-repo-tools +examples = + bigquery/api + blog/introduction_to_data_models_in_cloud_datastore + cloud_logging/api + compute/api + compute/autoscaler + datastore/api + managed_vms/cloudsql + managed_vms/datastore + managed_vms/disk + managed_vms/extending_runtime + managed_vms/hello_world + managed_vms/hello_world_compat + managed_vms/memcache + managed_vms/pubsub + managed_vms/static_files + managed_vms/storage + monitoring/api + storage/api +setenv = + PYTHONPATH=. -[testenv:requpdate] +[testenv:pep8] +deps = + flake8 + flake8-import-order commands = - bash -c "find . -name requirements\*.txt |\ - xargs -P 4 -n 1 gcp-python-repo-tools update-requirements" -whitelist_externals = - bash - find - xargs - gcp-python-repo-tools + flake8 --builtin=gettext --max-complexity=10 --import-order-style=google {posargs} -[testenv:gae] +[testenv:py27] deps = {[testenv]deps} -rrequirements-py27-dev.txt commands = - # Create a lib directory, otherwise, the vendor library will explode. - mkdir -p lib - nosetests --with-gae \ - --gae-app=appengine/resources/app.yaml \ - --logging-level=INFO \ - --with-xunit \ - --xunit-testsuite-name gae \ - --xunit-file nosetests-gae.xml \ - {[testenv]commonargs} \ - {posargs:appengine} -setenv = - PYTHONPATH={env:GAE_PYTHONPATH:} -whitelist_externals = mkdir + python scripts/run-tests.py {posargs:{[testenv]examples}} -[testenv:py27] +[testenv:py27-all] deps = - {[testenv]deps} - -rrequirements-py27-dev.txt + {[testenv:py27]deps} commands = - nosetests \ - --exclude-dir=appengine \ - {[testenv]commonargs} \ - {posargs:-a '!slow,!flaky'} + python scripts/run-tests.py \ + --junit \ + --run-slow \ + {posargs:{[testenv]examples}} [testenv:py34] basepython = python3.4 deps = {[testenv]deps} -rrequirements-py34-dev.txt -commands = - nosetests \ - --exclude-dir=appengine \ - # Websockets doesn't work with py34 because of gevent dep. - --exclude-dir=managed_vms/websockets \ - {[testenv]commonargs} \ - {posargs:-a '!slow,!flaky'} - -[testenv:py27-all] -deps = - {[testenv:py27]deps} -commands = - nosetests \ - --exclude-dir=appengine \ - {[testenv]commonargs} \ - --with-xunit \ - --xunit-testsuite-name py27 \ - --xunit-file nosetests-py27.xml \ - {posargs} +commands = + python scripts/run-tests.py {posargs:{[testenv]examples}} [testenv:py34-all] basepython = python3.4 deps = {[testenv:py34]deps} -commands = - nosetests \ - --exclude-dir=appengine \ - --exclude-dir=managed_vms/websockets \ - {[testenv]commonargs} \ - --with-xunit \ - --xunit-testsuite-name py34 \ - --xunit-file nosetests-py34.xml \ - {posargs} +commands = + python scripts/run-tests.py \ + --junit \ + --run-slow \ + {posargs:{[testenv]examples}} -[testenv:pep8] -deps = - flake8 - flake8-import-order +[testenv:gae] +deps = + {[testenv]deps} + -rrequirements-py27-dev.txt +examples = + appengine/app_identity/signing + appengine/bigquery + appengine/blobstore + appengine/cloudsql + appengine/images + appengine/localtesting + appengine/logging/reading_logs + appengine/logging/writing_logs + appengine/mailgun + appengine/multitenancy + appengine/ndb/modeling + appengine/ndb/overview + appengine/ndb/transactions + appengine/storage commands = - flake8 --builtin=gettext --max-complexity=10 --import-order-style=google {posargs} + # Create a lib directory, otherwise, the vendor library will explode. + mkdir -p lib + python scripts/run-tests.py {posargs:{[testenv:gae]examples}} +setenv = + PYTHONPATH=.:{env:GAE_PYTHONPATH:} +whitelist_externals = mkdir + +[testenv:gae-all] +deps = + {[testenv:gae]deps} +commands = + # Create a lib directory, otherwise, the vendor library will explode. + mkdir -p lib + python scripts/run-tests.py \ + --junit \ + --run-slow \ + {posargs:{[testenv:gae]examples}} +setenv = + PYTHONPATH=.:{env:GAE_PYTHONPATH:} +whitelist_externals = mkdir + +[testenv:reqcheck] +commands = + bash -c "find . -name requirements\*.txt |\ + xargs -P 4 -n 1 gcp-python-repo-tools check-requirements" +whitelist_externals = + bash + find + xargs + gcp-python-repo-tools + +[testenv:requpdate] +commands = + bash -c "find . -name requirements\*.txt |\ + xargs -P 4 -n 1 gcp-python-repo-tools update-requirements" +whitelist_externals = + bash + find + xargs + gcp-python-repo-tools [flake8] exclude=container_engine/django_tutorial/polls/migrations/* + +[pytest] +addopts = -x --no-success-flaky-report --cov --cov-config .coveragerc --cov-append --cov-report= +