Skip to content

Commit c77d0cf

Browse files
committed
Merge pull request #237 from GoogleCloudPlatform/nox
Auto-detect directories to test.
2 parents 7bd7aeb + c07f3c0 commit c77d0cf

File tree

8 files changed

+43
-57
lines changed

8 files changed

+43
-57
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ include =
88
datastore/*
99
managed_vms/*
1010
monitoring/*
11+
speech/*
1112
storage/*
1213
[report]
1314
exclude_lines =

TESTING.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ The tests in this repository are system tests and run against live services, the
44

55
Before you can run tests locally you must have:
66

7-
* The latest [tox](https://tox.readthedocs.org/en/latest/),
7+
* The latest [nox](https://nox.readthedocs.org/en/latest/),
88
[pip](https://pypi.python.org/pypi/pip), and [gcp-python-repo-tools](https://pypi.python.org/pypi/gcp-python-repo-tools) installed.
99

10-
$ sudo pip install --upgrade tox pip gcp-python-repo-tools
10+
$ sudo pip install --upgrade nox-automation pip gcp-python-repo-tools
1111

1212
* The [Google Cloud SDK](https://cloud.google.com/sdk/) installed. You
1313
can do so with the following command:
@@ -50,29 +50,35 @@ If you want to run the Google App Engine tests, you will need:
5050

5151
### Test environments
5252

53-
We use [tox](https://tox.readthedocs.org/en/latest/) to configure
54-
multiple python environments:
53+
We use [nox](https://nox.readthedocs.org/en/latest/) to configure
54+
multiple python sessions:
5555

56-
* ``py27`` and ``py34`` contains tests for samples that run in a normal Python 2.7 pr 3.4 environment. This is everything outside of the ``appengine`` directory that isn't slow or flaky.
57-
* ``py27-all`` and ``py34-all`` runs all tests except for App Engine tests. This can time some time and some tests are flaky.
58-
* ``gae`` contains tests for samples that run only in Google App Engine. This is (mostly) everything in the ``appengine`` directory.
59-
* ``pep8`` just runs the linter.
56+
* ``tests`` contains tests for samples that run in a normal Python 2.7 or 3.4
57+
environment. This is everything outside of the ``appengine`` directory. It's
58+
parameterized to run all the tests using the 2.7 and 3.4 interpreters.
59+
* ``gae`` contains tests for samples that run only in Google App Engine. This is
60+
(mostly) everything in the ``appengine`` directory.
61+
* ``lint`` just runs the linter.
6062

61-
To run tests for a particular environment, invoke tox with the ``-e``
62-
flag:
63+
To see a list of the available sessions:
6364

64-
tox -e py27
65+
nox -l
6566

66-
To run one particular test suite or provide additional parameters to
67-
``py.test``, invoke tox like this:
67+
To run tests for a particular session, with a particular parameter, invoke nox
68+
with the ``-s`` flag:
6869

69-
toxe -e py27 -- storage/api
70+
nox -s "tests(interpreter='python2.7')"
7071

71-
### Adding new tests
72+
To run one particular session or provide additional parameters to ``py.test``,
73+
invoke nox like this:
74+
75+
nox -s tests -- storage/api
7276

73-
When adding a new top-level directory, be sure to edit ``.coveragerc`` and ``tox.ini`` to include it in tests and coverage reporting.
77+
### Adding new tests
78+
When adding a new top-level directory, be sure to edit ``.coveragerc`` to
79+
include it in coverage reporting.
7480

7581
To add new tests that require Google App Engine, please place them in
7682
the ``appengine`` directory if possible. If you place them elsewhere,
77-
you will need to modify ``tox.ini`` to make the environments
83+
you will need to modify ``nox.py`` to make the environments
7884
appropriately run or ignore your test.

nox.py

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,7 @@
2525
'-x', '--no-success-flaky-report', '--cov', '--cov-config',
2626
'.coveragerc', '--cov-append', '--cov-report=']
2727

28-
SAMPLES = [
29-
'bigquery/api',
30-
'blog/introduction_to_data_models_in_cloud_datastore',
31-
'cloud_logging/api',
32-
'compute/api',
33-
'compute/autoscaler/demo',
34-
'datastore/api',
35-
'managed_vms/cloudsql',
36-
'managed_vms/datastore',
37-
'managed_vms/disk',
38-
'managed_vms/extending_runtime',
39-
'managed_vms/hello_world',
40-
'managed_vms/hello_world_compat',
41-
'managed_vms/memcache',
42-
'managed_vms/pubsub',
43-
'managed_vms/static_files',
44-
'managed_vms/storage',
45-
'monitoring/api',
46-
'storage/api',
47-
]
48-
49-
GAE_SAMPLES = [
50-
'appengine/app_identity/signing',
51-
'appengine/bigquery',
52-
'appengine/blobstore',
53-
'appengine/cloudsql',
54-
'appengine/images',
55-
'appengine/localtesting',
56-
'appengine/logging/reading_logs',
57-
'appengine/logging/writing_logs',
58-
'appengine/mailgun',
59-
'appengine/memcache/guestbook',
60-
'appengine/multitenancy',
61-
'appengine/ndb/modeling',
62-
'appengine/ndb/overview',
63-
'appengine/ndb/transactions',
64-
'appengine/storage',
65-
]
28+
SESSION_TESTS_BLACKLIST = set(('appengine', 'testing'))
6629

6730

6831
def session_lint(session):
@@ -94,6 +57,21 @@ def session_reqcheck(session):
9457
session.run('gcprepotools', command, reqfile)
9558

9659

60+
def collect_sample_dirs(start_dir, blacklist=set()):
61+
"""Recursively collects a list of dirs that contain tests."""
62+
# Collect all the directories that have tests in them.
63+
for parent, subdirs, files in os.walk(start_dir):
64+
if any(f for f in files if f[-8:] == '_test.py'):
65+
# Don't recurse further, since py.test will do that.
66+
del subdirs[:]
67+
# This dir has tests in it. yield it.
68+
yield parent
69+
else:
70+
# Filter out dirs we don't want to recurse into
71+
subdirs[:] = [s for s in subdirs
72+
if s[0].isalpha() and s not in blacklist]
73+
74+
9775
@nox.parametrize('interpreter', ['python2.7', 'python3.4'])
9876
def session_tests(session, interpreter, extra_pytest_args=None):
9977
session.interpreter = interpreter
@@ -106,7 +84,8 @@ def session_tests(session, interpreter, extra_pytest_args=None):
10684

10785
# session.posargs is any leftover arguments from the command line, which
10886
# allows users to run a particular test instead of all of them.
109-
for sample in (session.posargs or SAMPLES):
87+
for sample in (session.posargs or
88+
collect_sample_dirs('.', SESSION_TESTS_BLACKLIST)):
11089
session.run(
11190
'py.test', sample,
11291
*pytest_args,
@@ -130,7 +109,7 @@ def session_gae(session, extra_pytest_args=None):
130109

131110
pytest_args = COMMON_PYTEST_ARGS + (extra_pytest_args or [])
132111

133-
for sample in (session.posargs or GAE_SAMPLES):
112+
for sample in (session.posargs or collect_sample_dirs('appengine')):
134113
session.run(
135114
'py.test', sample,
136115
*pytest_args,

0 commit comments

Comments
 (0)